互联网解决方案咨询

梦想有多大路就会有多远:作一颗IT量子
  首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

C# 3.0新特>使用查询表达式

Posted on 2008-02-23 18:06  互联网粒子  阅读(124)  评论(0编辑  收藏  举报
static void Main(string[] args)
 4        {
 5            var contacts = new List<Contact>();
 6
 7            contacts.Add(new Contact("Michael""520-331-2718",
 8                 "33140 SW Liverpool Lane""WA"));
 9            contacts.Add(new Contact("Jennifer""503-998-1177",
10                 "1245 NW Baypony Dr""OR"));
11            contacts.Add(new Contact("Sean""515-127-3340",
12                 "55217 SW Estate Dr""WA"));
13
14            var WAContacts =
15                    from c in contacts 
16         where c.State == "WA" 
17         select new { c.Name, c.Phone };
18
19            Console.WriteLine("Contacts in the state of Washington: ");
20            foreach (var c in WAContacts)
21            {
22                Console.WriteLine("Name: {0}, Phone: {1}", c.Name, c.Phone);
23            }

24        }