【发布时间】:2013-02-09 18:11:29
【问题描述】:
我正在制作一个 SchoolApp 程序来学习 C#,并且我正在尝试使用这个主要功能:
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 我也遇到了同样的问题,对它的了解不够。
编辑:感谢大家非常快速的回答。我得到了它的工作,现在将开始深入阅读答案,因此我不必再次提出相关问题!
【问题讨论】: