C# fo(); 打破 案例2: course.InputCourseInfo(); 打破 案例3: grade.InputGradeInfo(); 打破 案例4: course.PrintCourseInfo(); 打破 案例5: student.PRintStudentInfo(); 打破 案例6: grade.PrintGradeInfo(); 打破 案例0: WriteLine(“您已选择退出该程序祝您度过愉快的一天。”; 打破 } }而(accode!=0); Console.ReadKey(); } } }

C# fo(); 打破 案例2: course.InputCourseInfo(); 打破 案例3: grade.InputGradeInfo(); 打破 案例4: course.PrintCourseInfo(); 打破 案例5: student.PRintStudentInfo(); 打破 案例6: grade.PrintGradeInfo(); 打破 案例0: WriteLine(“您已选择退出该程序祝您度过愉快的一天。”; 打破 } }而(accode!=0); Console.ReadKey(); } } },c#,C#,当我说我复制了主。。。我的意思是,我获取了main下的所有代码,打开了一个新项目,将代码放回原处,然后程序运行。我尝试了关于使用try-and-catch的建议。。。但同样的问题仍然存在,当我按下start时,没有错误,cmd在一瞬间打开和关闭。当我按ctrl+f5键时,屏幕会出现,但只会显示“按任意键继续”。在主方法中添加一个try-catch,如下所示,以提示错误: static void Main(string[] args) { try {

当我说我复制了主。。。我的意思是,我获取了main下的所有代码,打开了一个新项目,将代码放回原处,然后程序运行。我尝试了关于使用try-and-catch的建议。。。但同样的问题仍然存在,当我按下start时,没有错误,cmd在一瞬间打开和关闭。当我按ctrl+f5键时,屏幕会出现,但只会显示“按任意键继续”。

在主方法中添加一个try-catch,如下所示,以提示错误:

static void Main(string[] args)  
            {  
    try
    {
                int accode ;  
                Student student = new Student() ;  
                Course course = new Course() ;  
                Grade grade = new Grade() ;  
                do  
                {  
                    Console.WriteLine(" 1.  Input Student information");  
...
                    Console.WriteLine(" 0.  Exit");  
                    Console.WriteLine(" Please select a choice from 0-8");  
                    accode = Console.ReadLine();  
                    switch (accode)  
                    {
    ...  
                    }  
                } while (accode != 0);   
    }
    catch (Exception Ex)
    {
       Console.Writeline("Exception: " + ex.Message);
    }
                Console.ReadKey();  
            } 

您的代码无法编译-您正在尝试从
Console.ReadLine()
int
变量分配
string
值。您需要做的第一件事是捕获
int.Parse(Console.ReadLine())
尝试解析非整数字符串时发生的异常。你需要做的第二件事就是读取字符串。
Sid
无需为整数。一旦您尝试自己调试问题,我们可能会帮助您。你的确切问题还不清楚,你的程序真的什么都没有做,你甚至没有告诉我们什么不起作用。你需要解释一下你的意思:“我已经把主文件复制到另一个文件中,运行了它,它起了作用……所以我真的很困惑。”就这样做吧!
static void Main(string[] args)  
            {  
    try
    {
                int accode ;  
                Student student = new Student() ;  
                Course course = new Course() ;  
                Grade grade = new Grade() ;  
                do  
                {  
                    Console.WriteLine(" 1.  Input Student information");  
...
                    Console.WriteLine(" 0.  Exit");  
                    Console.WriteLine(" Please select a choice from 0-8");  
                    accode = Console.ReadLine();  
                    switch (accode)  
                    {
    ...  
                    }  
                } while (accode != 0);   
    }
    catch (Exception Ex)
    {
       Console.Writeline("Exception: " + ex.Message);
    }
                Console.ReadKey();  
            }