public class Person : ICloneable
{
private string name;
private int age;
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
public int Age
{
get
{
return age;
}
set
{
age = value;
}
}
请高手帮忙啊
你继承是集合的接口吗?如果想通过Name来访问,可以在另外一个类定义person[]作为成员
public Person this[string nameIndex]
{
get
{
foreach(Person p in Persons)
{
if (p.Name=nameIndex)
{
return p;
}
}
}
}
class Persons : DictionaryBase
{
public void Add(string myKey, Person myPerson)
{
Dictionary.Add(myKey, myPerson);
}
public void Remove(string myKey)
{
Dictionary.Remove(myKey);
}
public Persons()
{
}
public Person this[string myKey]
{
get
{
return (Person)Dictionary[myKey];
}
set
{
Dictionary[myKey] = (Person)value;
}
}
}
[此贴子已经被作者于2006-12-21 3:25:51编辑过]
谢谢各位
我试试