1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23
| class Program { static void Main(string[] args) { Dictionary<int, Student> dictionary = new Dictionary<int, Student>(); Student stu1 = new Student(1, "小明", 20); Student stu2 = new Student(2, "小李", 21); Student stu3 = new Student(3, "小赵", 22); dictionary.Add(stu1.id, stu1); dictionary.Add(stu2.id, stu2); dictionary.Add(stu3.id, stu3); Console.WriteLine("请输入学号:"); int id = int.Parse(Console.ReadLine()); if (dictionary.ContainsKey(id)) { Console.WriteLine("学生信息为:{0}", dictionary[id]); } else { Console.WriteLine("您查找的学号不存在!"); } } }
|