私はC#について学ぶためにSchoolAppプログラムを作成しています。私はこの主な機能を機能させようとしています:
namespace SchoolApp
{
class Program
{
public static void Main(string[] args)
{
School sch = new School("Local School");
sch.AddStudent(new Student { Name = "James", Age = 22 }); // this function
sch.AddStudent(new Student { Name = "Jane", Age = 23 });
Console.WriteLine(sch); // this implementation
}
}
}
学校のクラス:
namespace SchoolApp
{
class School
{
public string name;
public School()
{
}
public School(string the_name)
{
name = the_name;
}
public void AddStudent(Student student)
{
}
}
}
学生クラス: 名前空間 SchoolApp
{
class Student
{
public int Age;
public string Name;
public Student()
{
Age = 0;
Name = "NONAME";
}
public string _name
{
get
{
return this.Name;
}
set
{
Name = value;
}
}
public int _age
{
get
{
return this.Age;
}
set
{
Age = value;
}
}
}
}
私は C# が初めてで、AddStudent を作成する方法と、WriteLine を使用してクラスを作成する方法についてかなり迷っています。出力は次の行に沿っている必要があります。
学校: 地元の学校 ジェームス 22 歳 ジェーン 23 歳
誰かが List<> を使用することを提案しました 私はそれについて十分に知らないという同じ問題にぶつかりました。
編集:非常に迅速な回答をありがとうございます。私はそれを機能させました。回答を詳細に読むことをお勧めしますので、関連する質問を再度する必要はありません!