什么是C#中的Where() [英] What is Where() in C#

查看:2013
本文介绍了什么是C#中的Where()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在参考文献中遇到了以下代码。我可以知道Where(r => r.TrackingState)是关于什么的?或者更具体地说,Where(=>)是什么?谢谢。

以下是代码:



 如果(_unitDtoListToGrid.DtoList.Where(R = <跨度类= 代码关键字>>  r.TrackingState == PLXS.GSF.DTO.Base.BaseDto.TrackingInfo.Created)。 ToList()。Count >   0 

解决方案
<预LANG = C# > <跨度类= 代码关键字 >如果(_unitDtoListToGrid.DtoList.Where(R = <跨度类= 代码 - 关键字>> r.TrackingState == PLXS.GSF.DTO.Base.BaseDto.TrackingInfo.Created)。ToList()。Count > 0

是一个Linq查询,它迭代在对象'_unitDtoListToGrid的实例中定义的List'DtoList。



对于List中的每个项目,进行测试以查看'TrackingState属性是否设置为某个值'PLXS.GSF.DTO.Base.BaseDto.TrackingInfo.Created



每个具有TrackingState值的项目都被置于一种临时枚举中,直到...才能直接访问...



使用'ToList()将枚举呈现为匿名类型的List:然后,计算所呈现的匹配集合的Count属性以确定'if表达式的布尔结果。


其中(r => r.TrackingState == value)

基本上,其中 IEnumerable方法 [ ^ ]根据谓词查找/过滤一系列值。

在这种情况下 r => r.TrackingState 表示函数(lambda表达式),用于将值 TrackingState 值进行比较



如需了解更多信息,请参阅:

LINQ(语言集成查询) [ ^ ]

LINQ:.NET语言集成查询 [ ^ ]

标准查询运算符概述 [ ^ ]

.NET标准查询运算符 [ ^ ]


其中扩展方法 [ ^ ]接受delegete方法,lambda表达式是最方便的方法来创建该委托。 here =>创建 lambda表达式 [ ^ ]。查看文档以获取示例以及有关lambda表达式的更多信息。


Hi, I have encounter the below codes in a reference. May I know what is the Where(r => r.TrackingState) is about? Or more specifically, what is Where( => ) about? Thank you.
Below are the codes:

if (_unitDtoListToGrid.DtoList.Where(r => r.TrackingState == PLXS.GSF.DTO.Base.BaseDto.TrackingInfo.Created).ToList().Count > 0)

解决方案

if (_unitDtoListToGrid.DtoList.Where(r => r.TrackingState == PLXS.GSF.DTO.Base.BaseDto.TrackingInfo.Created).ToList().Count > 0)

Is a Linq query that iterates over a List 'DtoList which is defined in an instance of an object '_unitDtoListToGrid.

For each item in the List, a test is made to see if the 'TrackingState Property is set to a certain value 'PLXS.GSF.DTO.Base.BaseDto.TrackingInfo.Created

Each item that has that 'TrackingState value is put into a kind of "temporary enumeration" that is not directly accessible until ...

The use of 'ToList() renders that enumeration into a List of an anonymous Type: then, the Count property of that rendered collection of matches is evaluated to determine the boolean result of the 'if expression.


Where(r => r.TrackingState == value)
Basically, Where is a IEnumerable method[^] to find/filter a sequence of values based on a predicate.
In this case r => r.TrackingState means a "function" (lambda expression), which is used to compare values TrackingState to value.

For further information, please see:
LINQ (Language-Integrated Query)[^]
LINQ: .NET Language-Integrated Query[^]
Standard Query Operators Overview[^]
The .NET Standard Query Operators[^]


Where is a Extension method[^] which accept delegete method, A lambda expression is the most convenient way to create that delegate. here => the syntax of creating lambda expression[^]. check the documentation for examples and more information about lambda expressions.


这篇关于什么是C#中的Where()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆