プロパティを持つオブジェクト全体を追加し、main関数の中でメソッドを呼び出すことは可能ですか?メソッドを追加する
下記のリストを使用して、アクション3を実行する必要があります。しかし、私はまた入れたくないList<Student> st = new List<Student>()
; WriteToFile()
とAddStudent()
の両方例えば
、私はそのリストを持っている:
static void Main(string[] args)
{
List<Student> st = new List<Student>();
Student st1 = new Student(1, "Mike", "Freelancer", 9);
st1.CalculateSalary();
Student st2 = new Student(2, "Bob", "CEO", 7);
st2.CalculateSalary();
Student st3 = new Student(3, "Tina", "CEO", 3);
st3.CalculateSalary();
do
{
Console.WriteLine("============================");
Console.WriteLine("1. Write To File");
Console.WriteLine("2. Read From File");
Console.WriteLine("3. Add Student");
Console.WriteLine("============================");
answer = Convert.ToInt32(Console.ReadLine());
switch (answer)
{
case 1:
WriteToFile(filePath);
Console.WriteLine("File Created!");
break;
case 2:
ReadFromFile(filePath);
break;
case 3:
Console.WriteLine("Add Student");
break;
}
} while (answer != 4);
}
すべてのヘルプははるかに高く評価されます。
なぜこの質問はC++とは関係がないのでしょうか? –
別のSOの意味は? – Kaloyan
なぜあなたは 'WriteToFile()'または 'AddStudent()'に 'List st = new List ();'を入れたのですか? 1つの方法は、おそらく既存の生徒データをファイルに書き込み、もう1つは新しい生徒をリストに追加します。あなたの質問は意味をなさない。 –