预览加载中,请您耐心等待几秒...
1/10
2/10
3/10
4/10
5/10
6/10
7/10
8/10
9/10
10/10

亲,该文档总共13页,到这已经超出免费预览范围,如果喜欢就直接下载吧~

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

c#关键字查询之select子句运用c#关键字查询之select子句运用引导语:在计算机中,select语句是最常用的数据查询语句。以下是小编整理的c#关键字查询之select子句运用,欢迎参考阅读!在查询表达式中,select子句可以指定将在执行查询时产生的值的类型。该子句的结果将基于前面所有子句的计算结果以及select子句本身中的所有表达式。查询表达式必须以select子句或group子句结束。下面的示例演示了查询表达式中的简单select子句。C# classSelectSample1{staticvoidMain(){//CreatethedatasourceList<int>Scores=newList<int>(){97,92,81,60};//Createthequery.IEnumerable<int>queryHighScores=fromscoreinScoreswherescore>80selectscore;//Executethequery.foreach(intiinqueryHighScores){Console.Write(i+"");}}}//Output:979281select子句产生的序列的'类型决定了查询变量queryHighScores的类型。在最简单的情况下,select子句仅指定范围变量。这会使返回的序列包含与数据源具有相同类型的元素。有关更多信息,请参见查询操作中的类型关系(LINQ)。不过,select子句还提供了一种功能强大的机制,可用于将源数据转换(或投影)为新类型。有关更多信息,请参见使用LINQ进行数据转换。示例下面的示例演示了select子句可能采用的所有不同形式。在每个查询中,请注意select子句和查询变量(studentQuery1、studentQuery2等)的类型之间的关系。C# classSelectSample2{//DefinesomeclassespublicclassStudent{publicstringFirst{get;set;}publicstringLast{get;set;}publicintID{get;set;}publicList<int>Scores;publicContactInfoGetContactInfo(SelectSample2app,intid){ContactInfocInfo=(fromciinapp.contactListwhereci.ID==idselectci).FirstOrDefault();returncInfo;}publicoverridestringToString(){returnFirst+""+Last+":"+ID;}}publicclassContactInfo{publicintID{get;set;}publicstringEmail{get;set;}publicstringPhone{get;set;}publicoverridestringToString(){returnEmail+","+Phone;}}publicclassScoreInfo{publicdoubleAverage{get;set;}publicintID{get;set;}}//TheprimarydatasourceList<Student>students=newList<Student>(){newStudent{First="Svetlana",Last="Omelchenko",ID=111,Scores=newList<int>(){97,92,81,60}},newStudent{First="Claire",Last="O'Donnell",ID=112,Scores=newList<int>(){75,84,91,39}},newStudent{First="Sven",Last="Mortensen",ID=113,Scores=newList<int>(){88,94,65,91}},newStudent{First="Cesar",Last="Garcia",ID=114,Scores=newList<int>(){97,89,85,82}},};//Separatedatasou