主题:关于关键字值集合使用的问题
/**程序说明:创建一个集合类People,它是Person类的集合
* 创建日期:2006年11月10日*/
using System;
using System.Collections;
namespace Aggregate
{
public class People:DictionaryBase
{
public People()
{
}
public void Add(Person newPerson)
{
Dictionary.Add(newPerson.Name,newPerson);
}
public void Remove(string name)
{
Dictionary.Remove(name);
}
//定义一个字符串索引符,这个索引符是Person类中人的姓名
public Person this [string name]
{
get
{
return (Person)Dictionary[name];
}
set
{
Dictionary[name] = value;
}
}
}
}
using System;
/*person类*/
namespace Aggregate
{
public class Person
{
private string name;
private int age;
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
public int Age
{
get
{
return age;
}
set
{
age = value;
}
}
}
}
namespace Aggregate
{
public class Run
{
static void Main(string[] args)
{
People myPeople = new People();
foreach(DictionaryEntry myEntry in myPeople)
{
Console.WriteLine("Name:{0}",((Person)myEntry.Value).Name);
}
Console.Read();
}
}
}
我的问题是在Run类中如何使用自己定义的关键字值name来向集合中进行添加,删除元素
* 创建日期:2006年11月10日*/
using System;
using System.Collections;
namespace Aggregate
{
public class People:DictionaryBase
{
public People()
{
}
public void Add(Person newPerson)
{
Dictionary.Add(newPerson.Name,newPerson);
}
public void Remove(string name)
{
Dictionary.Remove(name);
}
//定义一个字符串索引符,这个索引符是Person类中人的姓名
public Person this [string name]
{
get
{
return (Person)Dictionary[name];
}
set
{
Dictionary[name] = value;
}
}
}
}
using System;
/*person类*/
namespace Aggregate
{
public class Person
{
private string name;
private int age;
public string Name
{
get
{
return name;
}
set
{
name = value;
}
}
public int Age
{
get
{
return age;
}
set
{
age = value;
}
}
}
}
namespace Aggregate
{
public class Run
{
static void Main(string[] args)
{
People myPeople = new People();
foreach(DictionaryEntry myEntry in myPeople)
{
Console.WriteLine("Name:{0}",((Person)myEntry.Value).Name);
}
Console.Read();
}
}
}
我的问题是在Run类中如何使用自己定义的关键字值name来向集合中进行添加,删除元素