[C#] 纯文本查看 复制代码
using System;
using System.Collections.Generic;
using System.IO;
using System.Text;
namespace Student
{
class Program
{
static void Main(string[] args)
{
List<Student> studentList = new List<Student>();
Console.WriteLine("学生成绩系统");
do
{
Console.Write("请输入学生ID:");
int id = Convert.ToInt32(Console.ReadLine());
Console.Write("请输入学生名字:");
string name = Console.ReadLine();
Console.Write("请输入英语成绩:");
int englishaAchievement = Convert.ToInt32(Console.ReadLine());
Console.Write("请输入数学成绩:");
int mathAhievement = Convert.ToInt32(Console.ReadLine());
Console.Write("请输入语文成绩:");
int chineseAhievement = Convert.ToInt32(Console.ReadLine());
Console.Write("按Q保存退出,回车继续输入");
studentList.Add(new Student(id,name,englishaAchievement, mathAhievement, chineseAhievement));
} while (Console.ReadLine() != "q");
StreamWriter SW;
if (!File.Exists(@"stu.txt"))
File.Delete(@"stu.txt");
SW = File.CreateText(@"stu.txt");
foreach (var temp in studentList)
{
SW.WriteLine(temp);
}
SW.Close();
}
}
class Student
{
private int s_tudentID;
private string _name;
private int _englishaAchievement;
private int _mathAchievement;
private int _chineseAhievement;
public override string ToString()
{
return $"StudentId: {s_tudentID}, Name: {_name}, EnglishaAchievement: {_englishaAchievement}, MathAchievement: {_mathAchievement}, ChineseAhievement: {_chineseAhievement}";
}
public Student(int studentID,string name,int englishaAchievement,int mathAchievement,int chineseAhievement)
{
this.s_tudentID = studentID;
this._name = name;
this._englishaAchievement = englishaAchievement;
this._mathAchievement = mathAchievement;
this._chineseAhievement = chineseAhievement;
}
}
}