创建控制台应用程序,在点击项目右键添加-新建项-类命名为: Program类,详细代码如下:
using System; namespace Text_09_23Convert { class Program { class Student { public string stuNo = "3119070130"; public string Name; public string Sex; public double Math; public double Chi; public double Enl; public double tal() { double tal; //return Math+Chi+Enl; tal = Math + Chi + Enl; return tal; } public double avg() { double avg; avg = (Math + Chi + Enl) / 3; return avg; } public void input() { Console.WriteLine("请输入学号:"); stuNo = Console.ReadLine(); Console.WriteLine("请输入姓名"); Name = Console.ReadLine(); Console.WriteLine("请输入数学成绩:"); Math = double.Parse(Console.ReadLine()); Console.WriteLine("请输入英语成绩:"); Enl = double.Parse(Console.ReadLine()); Console.WriteLine("请输入语文成绩:"); Chi = double.Parse(Console.ReadLine()); } } static void Main(string[] args) { Student stu = new Student(); stu.input(); Console.WriteLine("{0}的总成绩为:{1},平均成绩为:{2}", stu.Name, stu.tal(), stu.avg()); Console.ReadKey(); } } }
结果: