我的对象数组只打印输入的最后一个对象C#

时间:2017-04-03 01:46:58

标签: c#

打印时我的对象数组只返回输入的最后一组对象的值。因此,如果我在最后输入一组值,它将只打印出最后一组数据。

命名空间classschedule {     课程     {

    static void Main(string[] args)
    {

        Course[] newarray = new Course[25];

        Course[ , ] mycoursearray = new Course[6,5];
        Course info = new Course();
        int sections, classregistration, periods;
        string names, classday;

        for (int x1 = 0; x1 < 6; x1++)
        {
            for (int y1 = 0; y1 < 5; y1++)
            {

                mycoursearray[x1, y1] = new Course();
            }
        }


        for (int x1 = 0; x1<5;x1++)
        {
            newarray[x1] = new Course();
        }

        int x = 0;
        int y = 0;
        for (int g = 0; g <= 4; g++)
        {
            for (int h = 0; h <= 5; h++)
            {
                info.busy = 0;
                info.section = 0;
                info.classize = 0;
                info.classname = "";
                mycoursearray[h, g] = info;
            }

        }




        for (int j = 0; j < 24; j++)
        {



            Console.WriteLine("please enter class name: ");
            names = Console.ReadLine();


            char choice = 'y';
            Console.WriteLine("please enter the section of your class: ");
            sections = Convert.ToInt32(Console.ReadLine());
           while (choice == 'y' || choice == 'Y')
            { if (sections <= 90)
                {

                    choice = 'n';
                }
            else
                {
                    Console.WriteLine("Section is to high must be below 90");

                    choice = 'n';



                }                                             
            }

            Console.WriteLine("Please enter the amount of students in the class: ");
            classregistration = Convert.ToInt32(Console.ReadLine());


            Console.WriteLine("Please enter the first letter of the day of the class **for thursday please type X");
            classday = Console.ReadLine();


            Console.WriteLine("Please enter your class period");
            periods = Convert.ToInt32(Console.ReadLine());

            x = periods - 1 ;
            if (classday == "M")
                y = 0;
            else if (classday == "T")
                y = 1;
            else if (classday == "W")
                y = 2;
            else if (classday == "X")
                y = 3;
            else if (classday == "F")
                y = 4;

                info.classname = names;
                info.section = sections;
                info.classize = classregistration;
                info.busy = 1;
                mycoursearray[x, y] = info;
                newarray[y+1] = info;






        }

    {
        for (int i = 0; i < 6; i++)
        {
            for (int j = 0; j < 5 ; j++)
            {
                Console.Write(mycoursearray[i, j].classname +"  " + mycoursearray[i, j].section+ "   " + mycoursearray[i, j].classize);
                //Console.Write(mycoursearray[i, j].section);
                //Console.Write(mycoursearray[i, j].classize);
            }
                Console.WriteLine();
        }
    }                      






        Console.ReadLine();






    }
    class Course
    {

        public int section;
        public string classname;
        public int classize;
        public int busy;


    }
}

}

0 个答案:

没有答案