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

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 { getset; }
public string LastName { getset; }
public string Counary { getset; }

public Person(string first, string last,string counary)
{
FirstName 
= first;
LastName 
= last;
Counary 
= counary;
}
}
}
Loopup集合类笔记

输出结果:

Loopup集合类笔记




本文转自黄聪博客园博客,原文链接:http://www.cnblogs.com/huangcong/archive/2010/05/13/1734605.html,如需转载请自行联系原作者

相关文章:

  • 2021-11-21
  • 2021-07-16
  • 2021-07-11
  • 2021-08-06
  • 2022-12-23
  • 2021-11-27
  • 2021-08-06
  • 2022-12-23
猜你喜欢
  • 2021-12-18
  • 2021-06-26
  • 2021-05-14
  • 2021-04-21
  • 2021-04-20
  • 2021-04-12
相关资源
相似解决方案