class Person
{
private int age;
private string name;
public Person(int age, string name)
{
this.age = age;
this.name = name;
}
public int Age
{
get
{
return this.age;
}
set
{
this.age = value;
}
}
public string Name
{
get
{
return this.name;
}
set
{
this.name = value;
}
}
public override string ToString()
{
return string.Format("age:{0}, name:{1}", this.age, this.name);
}
}
class Start
{
static void Main(string[] args)
{
Dictionary<string, Person> personDict = new Dictionary<string, Person>();
personDict.Add("key1", new Person(25, "cxm"));
personDict.Add("key2", new Person(24, "zqr"));
personDict.Add("key3", new Person(27, "xiaoming"));
foreach (var item in personDict)
{
Console.WriteLine(item);
Console.WriteLine("key:" + item.Key + " value:" + item.Value);
}
Console.WriteLine(personDict.Count);
Console.ReadLine();
}
}
C#_Dictionary<TKey, TValue>的使用
最新推荐文章于 2023-08-11 11:21:06 发布