C#学习笔记之——学生信息输入系统(Dictionary)
来源:互联网 发布:苏州市人工智能学会 编辑:程序博客网 时间:2024/06/05 07:38
创建一个学生类
public class Student{protected string name;protected string stuID;protected int score;public Student(){}public string Name{set{if (name == null)name = value;}get{return name;}}public string StuID{set{if (stuID == null)stuID = value;}get{return stuID;}}public int Score{set{score = value;}get{return score;}}}
创建dictionary存放学生信息,录入完毕用学生学号排序
Dictionary<int, Student> studentInfo = new Dictionary<int, Student> ();//Student stu = new Student ();Console.WriteLine ("please write down the student's information:(when write down \" \" (space) ,shut down)");Console.Write ("No.");int i;string a = Console.ReadLine ();while (a != " ") {Student stu = new Student ();Console.Write ("student's name:");stu.Name = Console.ReadLine ();Console.Write ("student's ID:");stu.StuID = Console.ReadLine ();Console.Write ("student's score:");stu.Score = int.Parse (Console.ReadLine ());i = int.Parse (a);studentInfo.Add (i, stu);Console.Write ("No.");a = Console.ReadLine ();}Dictionary<int, Student> studentIndo_SortedByValue = studentInfo.OrderBy(p=>p.Value.StuID).ToDictionary(p => p.Key, o => o.Value);foreach (var item in studentIndo_SortedByValue) {Console.WriteLine (item.Key + " " + item.Value.Name + " " + item.Value.StuID + " " + item.Value.Score);}
结果:
please write down the student's information:(when write down " " (space) ,shut down)
No.1
student's name:Pink
student's ID:03
student's score:89
No.2
student's name:Sia
student's ID:01
student's score:67
No.3
student's name:Ed
student's ID:02
student's score:45
No.
2 Sia 01 67
3 Ed 02 45
1 Pink 03 89
黄老板的粉不要打我,我也是随便举的例子QAQ
阅读全文
0 0
- C#学习笔记之——学生信息输入系统(Dictionary)
- C#学生信息注册系统
- C#学习笔记--ArrayList?List<T>?Dictionary
- 信息推荐系统学习笔记之概述
- 学生信息查询系统学习总结
- 必要的信息提示框——学生管理系统之用户体验
- 输入学生信息的!
- 学生信息的输入
- 输入\输出学生信息
- 输入/输出学生信息
- 输入/输出学生信息
- 输入/输出学生信息
- 学生信息管理系统之【修改信息窗口】
- 学生信息管理系统之修改数据信息
- 学生信息管理系统之查询数据信息
- C#学习笔记集合类型之Hashtable、Dictionary和SortedList(2)
- C#源代码—使用哈希表保存学生信息
- 十五、文件操作示例——学生信息录入系统
- AndroidStudio导入网上下载的代码慢及AndroidStudio不提示代码的解决方法
- Eclipse 接口开发(二)
- Ubuntu常用命令(hadoop学习笔记)
- 杂货边角(2):AT&T和INTEL汇编语法
- 使用百度BAE和新浪SAE部署web项目
- C#学习笔记之——学生信息输入系统(Dictionary)
- 69 个经典 Spring 面试题和答案
- C++——OOP(Object-Oriented Programming) vs. GP(Generic Programming)
- LeetCode 第7题 Reverse Integer (easy)——python
- 网站部署到Linux服务器上并添加https证书
- 科研生活
- malloc、calloc、realloc的区别
- jquery validate
- 转-关于书上说的“编译的时候分配内存”