黄聪

论SEO对人类的重要性,请看我的博客:hcsem.com

  博客园 :: 首页 :: 博问 :: 闪存 :: 新随笔 :: 联系 :: 订阅 订阅 :: 管理 ::

使用Loopup集合类管理相同键值的对象集

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Lookup
{
class Program
{
static void Main(string[] args)
{
Person graham
= new Person("Graham", "Hill", "USA");
Person emerson
= new Person("Emerson", "Fittipaldi", "USA");
Person hc
= new Person("Huang", "Cong", "CA");
List
<Person> listPerson = new List<Person>() { graham, emerson, hc };

Lookup
<string, Person> Persons = (Lookup<string, Person>)listPerson.ToLookup(r => r.Counary);

foreach (Person obj in Persons["USA"])
{
Console.WriteLine(obj.FirstName
+ " "+ obj.LastName);
}
}
}

public class Person
{
public string FirstName { get; set; }
public string LastName { get; set; }
public string Counary { get; set; }

public Person(string first, string last,string counary)
{
FirstName
= first;
LastName
= last;
Counary
= counary;
}
}
}

输出结果:

posted on 2010-05-13 15:23  黄聪  阅读(662)  评论(0编辑  收藏  举报