写一个运用到数组、枚举、强制转换和循环语句的控制台应用程序

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace CWork0408 {

    class Program     {

       public enum Student

        {

    stu1 = 1,

           stu2 = 2,

           stu3 = 3,

    stu4 = 4,

           stu5 = 5,

           stu6 = 6

        }

        static void Main(string[] args)

        {

            string[] student1=new string[6];

            student1[0] = "张梦婷";

            student1[1] = "杨明珠";

            student1[2] = "崔雄";

            student1[3] = "曹真";

            student1[4] = "马森";

            student1[5] = "慕安峰";

            int[] student2 = new int[6];

            student2[0] = Convert.ToInt32(Student.stu1);

            student2[1] = Convert.ToInt32(Student.stu2);

            student2[2] = Convert.ToInt32(Student.stu3);

            student2[3] = Convert.ToInt32(Student.stu4);

            student2[4] = Convert.ToInt32(Student.stu5);

            student2[5] = Convert.ToInt32(Student.stu6);

            Console.WriteLine("所有学生名:");

            for (int i = 0; i < student1.Length; i++)

            {

                Console.Write(student1[i]+"\t");

            }

            Console.WriteLine("所有学生编号:");

            for (int j = 0; j < student2.Length; j++)

            {

                Console.Write(student2[j] + "\t");

            }

            Console.WriteLine("\n");

            while (1 == 1)

            {

                Console.Write("请输入学生编号:");

                int id = int.Parse(Console.ReadLine());

                switch (id)

                {

                    case 1:

                        Console.WriteLine("1号学生" + student1[0]);

                        break;

                    case 2:

                        Console.WriteLine("2号学生" + student1[1]);

                        break;

                    case 3:

                        Console.WriteLine("3号学生" + student1[2]);

                        break;

                    case 4:

                        Console.WriteLine("4号学生" + student1[3]);

                        break;

                    case 5:

                        Console.WriteLine("5号学生" + student1[4]);

                        break;

                    case 6:

                        Console.WriteLine("6号学生" + student1[5]);

                        break;

                    default:

                        Console.WriteLine("您输入的学生编号不存在!");

                        break;

                }

                Console.WriteLine("\n");

            }

        }

    }

}

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。