2个回答
2013-03-28
展开全部
class Program
{
static void Main(string[] args)
{
MyClass cls = new MyClass();
cls[0].SayHi();
cls[1].SayHi();
cls[2].SayHi();
Console.ReadLine();
}
}
class MyClass
{
public MyClass(string name)
{
this._name = name;
this._student = new Student[3];
this._student[0] = new Student("张三",15);
this._student[1] = new Student("里斯", 16);
this._student[2] = new Student("啊毛", 17);
}
private string _name; public string Name
{
get { return _name; }
set { _name = value; }
}
private Student[] _student;
public Student this[int index]
{
get { return this._student[index]; }
set { this._student[index] = value; }
}
}
class Student
{
public Student(string name, int age)
{
this._name = name;
this._age = age;
}
private string _name; public string Name
{
get { return _name; }
set { _name = value; }
}
private int _age; public int Age
{
get { return _age; }
set { _age = value; }
}
public void SayHi()
{
Console.WriteLine("大家好,我叫{0},今年{1}岁。");
}
}
{
static void Main(string[] args)
{
MyClass cls = new MyClass();
cls[0].SayHi();
cls[1].SayHi();
cls[2].SayHi();
Console.ReadLine();
}
}
class MyClass
{
public MyClass(string name)
{
this._name = name;
this._student = new Student[3];
this._student[0] = new Student("张三",15);
this._student[1] = new Student("里斯", 16);
this._student[2] = new Student("啊毛", 17);
}
private string _name; public string Name
{
get { return _name; }
set { _name = value; }
}
private Student[] _student;
public Student this[int index]
{
get { return this._student[index]; }
set { this._student[index] = value; }
}
}
class Student
{
public Student(string name, int age)
{
this._name = name;
this._age = age;
}
private string _name; public string Name
{
get { return _name; }
set { _name = value; }
}
private int _age; public int Age
{
get { return _age; }
set { _age = value; }
}
public void SayHi()
{
Console.WriteLine("大家好,我叫{0},今年{1}岁。");
}
}
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询