Lookup类的使用

/*
Lookup类的使用 一键多值
*/
using System.Linq;
using System.Collections.Generic;

namespace Frank
{
	public class Test
    {
		//程序入口
        public static void Main(string[] args)
        {
			List<Racer> list = new List<Racer>();
			list.Add(new Racer("jack","wuhan"));
			list.Add(new Racer("tom","wuhan"));
			list.Add(new Racer("andy","beijing"));
			var look = list.ToLookup(r => r.City);
			foreach(Racer item in look["wuhan"])
			{
				System.Console.WriteLine(item.Name);
			}
			System.Console.WriteLine(look.GetType());
        }
	}
	public class Racer
	{
		public string Name{get;set;}
		public string City{get;set;}
		public Racer(string name,string city)
		{
			this.Name = name;
			this.City = city;
		}
	}
}

  

posted on 2013-12-06 14:43  wp456  阅读(258)  评论(0)    收藏  举报

导航