1

 

例如:

//1.实现附件《ListStudy》的功能            

List<gather> ga = new List<gather>();    

        // ArrayList ga = new ArrayList();   

          while (true)             {                 Console.Clear();    

             Console.WriteLine("集合当前包含{0}个数字,他们分别是\n", ga.Count);

                foreach (gather item in ga)   {                     Console.WriteLine(item.shuzi);                 }    

             Console.WriteLine("请输入一个数字,该数字将会加入到集合的末尾:");            

     int n = Convert.ToInt32(Console.ReadLine());         

        gather g = new gather();        

         g.shuzi = n;           

      ga.Add(g);             

    Console.WriteLine("是否继续输入(Y/N)");       

          string input = Console.ReadLine();        

         if (input.ToLower() == "y")   {                     continue;                 }         

        else                 {

                    Console.WriteLine("请输入一个数字:");   

                  int m = Convert.ToInt32(Console.ReadLine());   

                  Console.WriteLine("请该数字加入到集合的位置:");       

              int k = Convert.ToInt32(Console.ReadLine());       

             // ga.Insert(k, m);              

       Console.WriteLine("是否继续输入(Y/N)");   

                  string input1 = Console.ReadLine();   

                  if (input1 == "y") {                         continue;                     }    

                 else   {                         Console.WriteLine("是否清空集合(Y/N)");   

                      string input2 = Console.ReadLine();             

            if (input2 == "y")            

             {                             ga.Clear();                             continue;                         }           

              else                         {                             break;                         }                     }                 }             }

 

posted @ 2015-04-12 23:14  紫色贝与桔梗花  阅读(62)  评论(0编辑  收藏  举报