《C#控制台实现模拟学生管理系统.doc》由会员分享,可在线阅读,更多相关《C#控制台实现模拟学生管理系统.doc(5页珍藏版)》请在金锄头文库上搜索。
1、C#控制台模拟学生管理系统最终运行效果添加学生删除学生修改学生代码如下using System;using System.Collections.Generic;using System.Linq;using System.Text;namespace SGMS class Program static void Main(string args) List lstStudent = new List(); bool flag = true; while (flag) Console.WriteLine(-); Console.ForegroundColor = ConsoleColor.Re
2、d; Console.WriteLine(使用提示(按键-操作):A-添加 D-删除 C-修改 L-查看); Console.ForegroundColor = ConsoleColor.Gray; Console.WriteLine(-); ConsoleKey ck = Console.ReadKey(true).Key; switch (ck) case ConsoleKey.A: /Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine(请输入学生相关信息); /Console.ForegroundColor = Co
3、nsoleColor.Gray; Student stu = new Student(); Console.Write(学号:); stu.stuNo = Console.ReadLine().Trim(); Console.Write(姓名:); stu.stuName = Console.ReadLine().Trim(); Console.Write(性别:); stu.stuSex = char.Parse(Console.ReadLine().Trim(); Console.Write(年龄:); stu.stuAge = short.Parse(Console.ReadLine()
4、.Trim(); lstStudent.Add(stu); Console.WriteLine(添加成功); break; case ConsoleKey.D: if (lstStudent.Count = 0) Console.WriteLine(系统还未添加任何学生信息); else Console.Write(请输入要删除的学生的学号:); string no = Console.ReadLine().Trim(); for (int i = 0; i lstStudent.Count; i+) if (lstStudenti.stuNo = no) lstStudent.Remove(
5、lstStudenti); Console.WriteLine(删除成功); break; if (i = lstStudent.Count - 1) Console.WriteLine(抱歉!系统中没有这个学号); break; case ConsoleKey.C: if (lstStudent.Count = 0) Console.WriteLine(系统还未添加任何学生信息); else Console.Write(请输入要修改的学生的学号:); string no = Console.ReadLine().Trim() ; for (int i = 0; i lstStudent.Co
6、unt; i+) Student item = lstStudenti; if (item.stuNo = no) Console.Write(学号:); item.stuNo = Console.ReadLine().Trim(); Console.Write(姓名:); item.stuName = Console.ReadLine().Trim(); Console.Write(性别:); item.stuSex = char.Parse(Console.ReadLine().Trim(); Console.Write(年龄:); item.stuAge = short.Parse(Console.ReadLine().Trim(); lstStudenti = item; Console.WriteLine(修改成功!); break; if (i = lstStudent.Count - 1) Console.WriteLine(抱歉!系统中没有这个学号); break; case ConsoleKey.L: if (lstStudent.Count = 0)