All articles| All Pictures| All Softwares| All Video| Go home page| Write articles| Upload pictures

Reading number is top 10 articles
用C#.NET实现拖放操作_[Asp.Net教程]
精华:AJAX开发简略(第一部分)_[AJAX教程]
AJAX初体验之上手篇_[AJAX教程]
.net,2.0(c#)下简单的FTP应用程序_[Asp.Net教程]
获取所有用户表及根据表Id取得表字段信息_[SQL,Server教程]
asp.net,WebForm页面间传值方法_[Asp.Net教程]
PHP实例:用PHP实现广告轮播_[PHP教程]
微软.NET平台中类型使用的基本原理_.net资料_编程技术
[delphi语法3]布尔类型的使用方法
详细学习PHP中对文件和目录的操作方法_php资料_编程技术
Reading number is top 10 pictures
Household design comfortable contracted
青春清纯美女大集合2
The little woman's bright wire3
Sora aoi in China2
这两天,中国人民到处都可以“看海”了
真正的国产-非模拍 贵在是真实2
Kim jong il's mistress, national beauty JinYuJi actor1
网络游戏与脑残
The real super beauty11
什么叫国家
Download software ranking
WebService在.NET中的实战应用教学视频 → 第5集
I for your crazy
Unix video tutorial3
Twenty piece of palm leaf
Call Of Duty5
Such love down(擒爱记)
Tram sex maniac 2 (H) rar bag19
双旗镇刀客A
Tram sex maniac 2 (H) rar bag3
Unix video tutorial10
delv published in(发表于) 2014/1/6 9:05:43 Edit(编辑)
C#,3.0新特性初步研究,Part6:使用查询表达式_[Asp.Net教程]

C#,3.0新特性初步研究,Part6:使用查询表达式_[Asp.Net教程]

C# 3.0新特性初步研究 Part6:使用查询表达式_[Asp.Net教程]

查询表达式(Query Expression)
大家都应该对SQL语句不陌生吧,在C# 2.0之前,嵌入到代码中的SQL就是下面这个样子:
1public void Test()
2{
3SqlConnection c = new SqlConnection(…);
4 c.Open();
5 SqlCommand cmd = new SqlCommand(
6 @“SELECT c.Name, c.Phone // queries in quotes
7 FROM Customers c
8 WHERE c.City = @p0”
9 );
10 cmd.Parameters[“@po”] = “London”; // arguments loosely bound
11 DataReader dr = c.Execute(cmd);
12 while (dr.Read()) {
13 string name = r.GetString(0);
14 string phone = r.GetString(1); // results loosely typed
15 DateTime date = r.GetDateTime(2); // compiler can’t help catch mistakes
16 }
17 r.Close();
18}
在C# 3.0中,我们可以将“SQL语句”方便的运用到其他地方,当然这里并不是真正的SQL语句~~
我觉得我会在以后的开发过程中使用很多以下的类似代码:
1class Program
2 {
3 static void Main(string[] args)
4 {
5 var contacts = new List();
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 }
25 }
26
27 class Contact
28 {
29 public string Name;
30 public string Phone;
31 public string Address;
32 public string State;
33
34 public Contact(string name, string phone, string address, string state)
35 {
36 this.Name = name;
37 this.Phone = phone;
38 this.Address = address;
39 this.State = state;
40 }
41 }
其中出现的代码:
1var WAContacts =
2 from c in contacts
3 where c.State == "WA"
4 select new { c.Name, c.Phone };
是否与我们熟悉的SQL语句有着极大的相似性呢?Of Course!
到底是SQL梦见了C#,还是C#梦见了SQL……


来源:网络







添加到del.icio.us 添加到新浪ViVi 添加到百度搜藏 添加到POCO网摘 添加到天天网摘365Key 添加到和讯网摘 添加到天极网摘 添加到黑米书签 添加到QQ书签 添加到雅虎收藏 添加到奇客发现 diigo it 添加到饭否 添加到飞豆订阅 添加到抓虾收藏 添加到鲜果订阅 digg it 貼到funP 添加到有道阅读 Live Favorites 添加到Newsvine 打印本页 用Email发送本页 在Facebook上分享


Disclaimer Privacy Policy About us Site Map

If you have any requirements, please contact webmaster。(如果有什么要求,请联系站长)
Copyright ©2011-
uuhomepage.com, Inc. All rights reserved.