为什么不让我通过这个清单呢?

时间:2017-12-21 01:12:38

标签: c#

我在Students类中有一个传递给Grades类的列表。 但是,一旦Student课程中的方法完成,它就会返回到主菜单"他们可以选择输入成绩。基本上我需要将这个列表从Students Class传递回Controller类,然后传递给Grades Class。我该怎么做呢?

Students get = new Students( );
Grades grades = new Grades( );
Search run = new Search( );

do 
{
  Console.WriteLine("Please select assessment category: ");
  Console.WriteLine("________________________________________________________________________________");
  Console.WriteLine(" ");
  Console.WriteLine("\t\t\tPlease make a selection 1-4: ");
  Console.Write("\n\t\t\t1. Assignments.");
  Console.Write("\n\t\t\t2. Discussion Topics.");
  Console.Write("\n\t\t\t3. Exams.");
  Console.Write("\n\t\t\t4. Individual Project.");
  Console.Write("\n\t\t\t5. Go Back to main menu.");
  Console.WriteLine("");  
  Console.WriteLine("___________________________________________________");

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

switch ( decision )
    {
     case 1:
         Console.Clear( );
         get.AddStudent();
         break;
     case 2:
         Console.Clear( );
         grades.EnterGrades(List<string> addedStudents);
         break;
     case 3:
         Console.Clear( );
         run.StudentSearch( );
         break;
     case 4:
         retry = "no";
         Console.Clear();
         break;
     default:
         Console.WriteLine("\nThat is not a valid option.");
         Console.WriteLine("Would you like to retry? Type 'yes' or 'no'.");
         retry = Console.ReadLine();
         Console.Clear();
         break;
     }

}while (retry != "no");      

1 个答案:

答案 0 :(得分:4)

因为您无法在传递它的位置声明变量。尝试:

 case 2:
     Console.Clear( );
     List<string> addedStudents = new List<string>();
     grades.EnterGrades(addedStudents);
     break;

然而,我认为整个事情从根本上来说更加错误。