字符串作为索引值
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConTest
{
class Teacher
{
private Dictionary<string, Student> students = new Dictionary<string, Student>();
public Student this[string name]
{
get
{
return students[name];
}
set
{
students[name] = value;
}
}
}
}
using System;
namespace ConTest
{
public class ConditionalBreakpoint
{
private double[] dataArray;
public double[] DataArray
{
get { return dataArray; }
set { dataArray = value; }
}
public static void Main()
{
Student studentGan = new Student("Gan",21,"2");
Student studentQuan = new Student("Quan", 22, "3");
Student studentFu = new Student("Fu", 23, "4");
Teacher teacher = new Teacher();
teacher[studentGan.Name] = studentGan;
teacher[studentQuan.Name] = studentQuan;
teacher[studentFu.Name] = studentFu;
Console.WriteLine(teacher["Gan"].Name+" "+teacher["Gan"].Age+" "+teacher["Gan"].ClassName);
Console.WriteLine(teacher["Quan"].Name + " " + teacher["Quan"].Age + " " + teacher["Quan"].ClassName);
Console.WriteLine(teacher["Fu"].Name + " " + teacher["Fu"].Age + " " + teacher["Fu"].ClassName);
Console.Read();
}
}
}