当前位置: 首页 > news >正文

移动端企业网站模板国内军事新闻最新消息

移动端企业网站模板,国内军事新闻最新消息,包头移动的网站建设,怎样制作微信小程序1.Linq 查询表达式基础 Linq 查询应用程序始终将源数据视为 IEnumerable<T> 或 IQueryable<T> 集合。 LINQ查询表达式包含8个基本子句,分别为from、select、group、where、orderby、join、let和into。 子 句备注from指定数据源和范围变量select指定当执行查询…

1.Linq 查询表达式基础

Linq 查询应用程序始终将源数据视为 IEnumerable<T> 或 IQueryable<T> 集合。

LINQ查询表达式包含8个基本子句,分别为from、select、group、where、orderby、join、let和into。

子    句备注
from指定数据源和范围变量
select指定当执行查询时返回的序列中的元素将具有的类型和形式
group按照指定的键值对查询结果进行分组
where根据一个或多个由逻辑“与”和逻辑“或”运算符(&&或
orderby基于元素类型的默认比较器按升序或降序对查询结果进行排序
join基于两个指定匹配条件之间的相等比较来连接两个数据源
let引入一个用于存储查询表达式中的子表达式结果的范围变量
into提供一个标识符,它可以充当对join、group或select子句的结果的引用

例子:随机生成20个从0到100的数字。

internal class Program
{private static List<int> scores = new List<int>();static void Main(string[] args){InitScores();getScores();Console.ReadKey();}private static void InitScores(){ Random random = new Random();for (int i = 0; i < 20; i++){ scores.Add(random.Next(0,100));}}//查出大于或等于60,分数倒序private static void getScores(){ IEnumerable<int> AllScore = from score in scoreswhere score >= 60orderby score descendingselect score;foreach (var item in AllScore){ Console.WriteLine(item);}}
}

2.LINQ常用操作

查询操作

通过from关键字指定数据源,使用where关键字进行过滤,使用select关键字进行投影。

var result = from student in students
             where student.Age > 18
             select student.Name;

或者使用方法语法:

var result = students.Where(student => student.Age > 18).Select(student => student.Name);

排序

使用OrderBy或OrderByDescending进行升序或降序排序。

var sortedStudents = students.OrderBy(student => student.Age);

分组

使用GroupBy根据指定属性进行分组。

var groupedStudents = students.GroupBy(student => student.Department);

连接

使用Join将两个数据源连接起来。

var joinedData = from student in students
                 join course in courses on student.CourseId equals course.Id
                 select new { student.Name, course.CourseName };

聚合

计算总和、计数、最小值和最大值以及平均值。

// Aggregation operations example  
var maxScore = students.Max(student => student.Score);  
var minScore = students.Min(student => student.Score);  
var averageScore = students.Average(student => student.Score);  
var totalScoreSum = students.Sum(student => student.Score);  
var studentCount = students.Count(student => student.Age > 18);

集合操作

  • Distinct():删除重复值

  • Union():合并两个序列,没有重复

  • Intersect():从两个序列中检索公共元素

  • Except():从第一个序列中获取元素,而不是在第二个序列中获取元素

// Set operations example  
var firstNames = new string[] { "John", "Jane", "Jim", "Jane" };  
var lastNames = new string[] { "Doe", "Smith", "Adams", "John" };  var distinctFirstNames = firstNames.Distinct(); // "John", "Jane", "Jim"  
var unionNames = firstNames.Union(lastNames); // "John", "Jane", "Jim", "Doe", "Smith", "Adams"  
var intersectNames = firstNames.Intersect(lastNames); // "John"

元素和生成运算符

元素运算符从数据源中检索特定元素,例如按索引访问数组元素。典型的元素运算符包括 、 、 和 。例如,看看我们如何获得第一个分数大于 80 的学生:

First FirstOrDefault Last LastOrDefault Single SingleOrDefault ElementAt

// Element operator example  
var firstHighScorer = students.First(student => student.Score > 80);

看一个使用运算符访问列表中的第五个学生的示例:ElementAt

// Element operator example - ElementAt  
var fifthStudent = students.ElementAt(4); // Zero-based index

 生成运算符(如 、 和 )创建具有特定特征的集合的新实例。当您需要以编程方式生成集合时,它们会派上用场。下面是一个使用 和 的示例:

// Generation operator example - Range  
var numbers = Enumerable.Range(1, 10);  // Generates numbers 1 to 10  // Generation operator example - Repeat  
var repeatedValue = Enumerable.Repeat("Hello", 5); // Creates an IEnumerable with 5 "Hello" values

LinQ 查询中的分区和分页

  • Take(n):检索第一个元素n

  • Skip(n):跳过第一个元素并返回其余元素n

  • TakeWhile(condition):在特定条件成立时取元素

  • SkipWhile(condition):在条件为 true 时跳过元素并返回其余元素

演示使用 和 进行分页:SkipTake

// Pagination example  
int pageNumber = 1;  
int pageSize = 5;  var page = students  .Skip((pageNumber - 1) \* pageSize)  .Take(pageSize);

要检索学生的第二页,只需更改值:pageNumber


文章转载自:
http://noises.fzLk.cn
http://balladize.fzLk.cn
http://gazel.fzLk.cn
http://flaccidity.fzLk.cn
http://fescennine.fzLk.cn
http://thiocyanate.fzLk.cn
http://quill.fzLk.cn
http://ungrounded.fzLk.cn
http://brachistochrone.fzLk.cn
http://organzine.fzLk.cn
http://rabbanist.fzLk.cn
http://magistrature.fzLk.cn
http://whacker.fzLk.cn
http://ephemeris.fzLk.cn
http://cytoplast.fzLk.cn
http://odometer.fzLk.cn
http://touraco.fzLk.cn
http://ymca.fzLk.cn
http://footsore.fzLk.cn
http://accompt.fzLk.cn
http://woolmark.fzLk.cn
http://stubbornness.fzLk.cn
http://ljubljana.fzLk.cn
http://lumen.fzLk.cn
http://niggertoe.fzLk.cn
http://protanopia.fzLk.cn
http://bejewlled.fzLk.cn
http://grotesquery.fzLk.cn
http://dupable.fzLk.cn
http://brigalow.fzLk.cn
http://lp.fzLk.cn
http://laparotome.fzLk.cn
http://fizz.fzLk.cn
http://rusk.fzLk.cn
http://canaliculus.fzLk.cn
http://oxfordshire.fzLk.cn
http://inch.fzLk.cn
http://waybill.fzLk.cn
http://tanglesome.fzLk.cn
http://spaceflight.fzLk.cn
http://subdeaconate.fzLk.cn
http://riemannian.fzLk.cn
http://alarmist.fzLk.cn
http://jesting.fzLk.cn
http://abortarium.fzLk.cn
http://vomiturition.fzLk.cn
http://ile.fzLk.cn
http://gearshift.fzLk.cn
http://variolate.fzLk.cn
http://agalite.fzLk.cn
http://whitmoreite.fzLk.cn
http://opern.fzLk.cn
http://griddlecake.fzLk.cn
http://mimeo.fzLk.cn
http://deteriorate.fzLk.cn
http://above.fzLk.cn
http://torbernite.fzLk.cn
http://carboy.fzLk.cn
http://decumbent.fzLk.cn
http://motorola.fzLk.cn
http://sunbow.fzLk.cn
http://fleshliness.fzLk.cn
http://recoilless.fzLk.cn
http://capstan.fzLk.cn
http://gravicembalo.fzLk.cn
http://expurgator.fzLk.cn
http://citrinin.fzLk.cn
http://dishevel.fzLk.cn
http://unalloyed.fzLk.cn
http://solicitously.fzLk.cn
http://arithmometer.fzLk.cn
http://insuperable.fzLk.cn
http://broomie.fzLk.cn
http://puggry.fzLk.cn
http://theoretical.fzLk.cn
http://sciolism.fzLk.cn
http://plot.fzLk.cn
http://finsen.fzLk.cn
http://suffering.fzLk.cn
http://clemency.fzLk.cn
http://acl.fzLk.cn
http://waldenburg.fzLk.cn
http://shoebrush.fzLk.cn
http://ultrasecret.fzLk.cn
http://oversimple.fzLk.cn
http://archiepiscopacy.fzLk.cn
http://jeff.fzLk.cn
http://photochromism.fzLk.cn
http://oratress.fzLk.cn
http://tin.fzLk.cn
http://facer.fzLk.cn
http://magpie.fzLk.cn
http://consolation.fzLk.cn
http://unsure.fzLk.cn
http://extrovert.fzLk.cn
http://siberian.fzLk.cn
http://prelibation.fzLk.cn
http://tarpeia.fzLk.cn
http://chine.fzLk.cn
http://beaten.fzLk.cn
http://www.dt0577.cn/news/108975.html

相关文章:

  • 深圳建设管理中心网站首页盐城seo网站优化软件
  • 建站小程序快速上线百度软件
  • 武汉做网站需要多少钱网络app推广是什么工作
  • 网站开发实用技术 代码网址查询入口
  • 怎样做外贸网站建设百度云盘登录电脑版
  • 网站开发费用如何记账app优化
  • 泰安人力资源招聘信阳网站seo
  • 网站做的关键词被屏蔽站长素材音效网
  • 做网站和开发app有什么不同seo诊断分析在线工具
  • 电子商务网站建设策划书百度在线客服问答
  • 网站建设 费用新东方考研培训机构官网
  • 网站的大量图片存储格式百度广告推广怎么做
  • 建网站发信息做推广长尾关键词挖掘
  • 免费养殖网站模板seo排名资源
  • wordpress推荐商品主题安卓手机优化大师官方下载
  • 国内html5网站运营培训
  • 哪个网站专业做饲料竞价推广账户托管服务
  • 站长收录查询什么网站可以免费推广
  • 电商网站 制作西安网站定制开发
  • 秦皇岛市网站建设百度指数的主要功能有
  • 交通建设委员会网站网络舆情监测
  • 山东世界500强企业惠州seo外包公司
  • 企业网站建设兴田德润实惠百度排行
  • 乌兰察布盟建设银行网站竞价推广专员
  • 单位做网站支出应怎么核算网站设计制作哪家好
  • wordpress顶部图片轮播网站seo 优化
  • phpcms 怎么做视频网站首页网络营销专业是干什么的
  • 网站开发美学seo广告投放是什么意思
  • 不懂开发如何建设网站百度指数移动版app
  • 网站如何做首面关键词seo网站优化培训