命名空间:System.Collections 命名空间

1.常用的预定义集合类

(1)ArrayList类(动态数组类型)
c#_5.集合
c#_5.集合
c#_5.集合创建动态数组:
ArrayList 列表对象名 = new ArrayList( );
例如, ArrayList list = new ArrayList();
list.Add(“小强”);
list.Add(30);
c#_5.集合
(2) 哈希表类
c#_5.集合
c#_5.集合
c#_5.集合
(3)作业:学生管理系统
c#_5.集合
程序:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections;

namespace student_contr
{
    class Program
    {
        static void Main(string[] args)
        {   Console.WriteLine("欢迎使用2018级学生管理系统");
            Console.WriteLine("**************************************");        
            string A,B,C,D,E;
            string dowhat,name,id; 
            int   redo=1;
            int flag=1;
            int count = 1;
            Hashtable ht = new Hashtable();
            while (redo == 1)
            {
                Console.WriteLine("请选择如下操作");
                Console.WriteLine("A.添加  B.查询  C.删除 D.修改  E.退出系统");
                dowhat = Console.ReadLine();
                switch (dowhat)
                { 
                    case "A"://添加功能
                        Console.WriteLine("请添加学生学号");
                        while (count == 1)//判断是否是第一次添加,如果是第一次,则不用判断学号键是否重复
                        {
                            id = Console.ReadLine();
                            Console.WriteLine("请添加学生姓名");
                            name = Console.ReadLine();
                            ht.Add(id, name);
                            count = 0;
                            
                        }
                        
                        while(count>1)
                        {
                            id = Console.ReadLine();
                            while (ht.Contains(id))
                            {
                               
                                Console.WriteLine("您输入的学号重复,请重新输入");
                                id = Console.ReadLine();
                               
                              
                            }
                            if (!(ht.Contains(id)))
                            {
                                
                                Console.WriteLine("请添加学生姓名");
                                name = Console.ReadLine();
                                ht.Add(id, name);
                                count = 0;
                            }
                        }
                        Console.WriteLine("是否再进行其他操作?1.继续 2.不继续");
                        redo = int.Parse(Console.ReadLine());
                        count=count+2;//注意这里一定是+比1大的数
                        break;
                    case "B"://查询功能
                        Console.WriteLine("请输入所要查询学生的学号");
                        id = Console.ReadLine();
                        if (ht.Contains(id))
                            Console.WriteLine(ht[id]);
                        else
                            Console.WriteLine("学生信息不存在");
                        Console.WriteLine("是否再进行其他操作?1.继续 2.不继续");
                        redo = int.Parse(Console.ReadLine());
                        break;
                    case "C"://删除功能
                        Console.WriteLine("请输入所要删除学生的学号");
                        id = Console.ReadLine();
                        if (ht.Contains(id))
                        {
                            ht.Remove(id);
                            Console.WriteLine("已删除!");
                        }
                        else
                        {
                            Console.WriteLine("您所要删除的信息不存在!请重新输入:所要删除学生的学号");
                        }                      
                        Console.WriteLine("是否再进行其他操作?1.继续 2.不继续");
                        redo = int.Parse(Console.ReadLine());
                        break;
                    case "D"://修改功能
                        { Console.WriteLine("请输入所要修改学生的学号");
                        id = Console.ReadLine();
                        while (!ht.Contains(id))//首先判断了学号信息是否存在
                            {
                               
                                Console.WriteLine("您输入的学号不存在,请重新输入");
                                id = Console.ReadLine();
                               
                              
                            }
                         if (ht.Contains(id))
                            {
                               Console.WriteLine("该学号下学生的姓名为{0},您要修改为:",ht[id]);
                               ht[id] = Console.ReadLine();
                               Console.WriteLine("已经修改");
                            }
                        }
                        Console.WriteLine("是否再进行其他操作?1.继续 2.不继续");
                        redo = int.Parse(Console.ReadLine());
                        break;//退出系统
                      case "E":
                      {redo = 0;
                        break;}
                       

                }
            }
     
           
        }
    }
}

相关文章:

  • 2022-12-23
猜你喜欢
  • 2022-02-24
  • 2021-07-28
  • 2021-10-23
  • 2021-06-05
  • 2021-10-21
相关资源
相似解决方案