关于C#的一个小问题,高手帮下忙

来源:百度知道 编辑:UC知道 时间:2024/06/04 06:45:24
一个索引的问题,小弟我没搞懂~~
程序的意思是假如我打名字,就可以搜出这个人的号码,反之,打号码可以搜出姓名,我的原程序是这样的,VS2008 窗口运行的.就是那get里不知道应该怎么写,高手解决一下..
namespace WindowsFormsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
telephoneList thetelephone = new telephoneList();
thetelephone.initialize();
this.textBox1.Text = thetelephone["王五"].ToString();
//this.textBox1.Text = thetelephone[123456];

}

public class Student
{
public String name;
public int ID;
}

public class telephoneList
{
private Student[] Students;
public void initialize()
{

public String this[int theID]
{
get
{
Student stu = null;
if (Students.Length > 0)
{
for (int i = 0; i < Students.Length; i++)
{
if (Students[i].ID == theID)
{
stu = Students[i];
break;
}
}
} return stu.name;
}

}

public int this[String theName]
{
get
{
Student stu = null;
if (Students.Length > 0)
{
for (int i = 0; i < Students.Length;