请帮忙查查C#中索引应用代码

来源:百度知道 编辑:UC知道 时间:2024/06/05 18:17:38
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace eight
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void Form1_Load(object sender, EventArgs e)
{
telephonelist thetelephonelist = new telephonelist();
thetelephonelist.initialize();
this.textBox1.Text = thetelephonelist["张三"].ToString();
}
}
/*
public class book
{
public string temp = "";
public string this[int index]
{
get { return temp; }
set { temp = value; }
}
}
//*/

public student this[int id] //索引返回的是对象本身
{
get {
for(int i = 0;i<students.Length;i++){

if(students[i].id == id)
return students[i];
}
}
}

你原来的,通过id找ID.不是无聊嘛