请问C#如何用索引器通过名字进行访问?

来源:百度知道 编辑:UC知道 时间:2024/06/11 07:02:34
using System;
using System.Collections.Generic;
using System.Text;
public class student
{
public student(string name, string hobby)
{
this.name = name;
this.hobby = hobby;
}
private string name;

public string Name
{
get { return name; }
set { name = value; }
}
private string hobby;

public string Hobby
{
get { return hobby; }
set { hobby = value; }
}
public void show()
{
Console.WriteLine("我叫{0},我喜欢{1}", name, hobby);
}
}
class MyClass
{
string name;
public MyClass()
{
this.stu = new student[3];
stu[0] = new student("张学友", "唱歌");
stu[1] = new student("郭富城", "跳舞");
stu[2] = new student("刘德华",

using System;
using System.Collections.Generic;
using System.Text;
public class student
{
public student(string name, string hobby)
{
this.name = name;
this.hobby = hobby;
}
private string name;

public string Name
{
get { return name; }
set { name = value; }
}
private string hobby;

public string Hobby
{
get { return hobby; }
set { hobby = value; }
}
public void show()
{
Console.WriteLine("我叫{0},我喜欢{1}", name, hobby);
}
}
class MyClass
{
string name;
public MyClass()
{
this.stu = new student[3];
stu[0] = new student("张学友", "唱歌");
stu[1] = new student("郭富城", "跳舞");
stu[2] = new student("刘德华", "演戏");
}
private student[] stu;

public student[] Stu
{
get { return stu;