当我打下以下一线时,我总是收到真实情况,不管“当地”是否出现在加入<编码>的
if (objUserRoles.Select(x => (x.Role.Role1 == "local")).Count() > 0)
我的同仁是否正确?
当我打下以下一线时,我总是收到真实情况,不管“当地”是否出现在加入<编码>的
if (objUserRoles.Select(x => (x.Role.Role1 == "local")).Count() > 0)
我的同仁是否正确?
What you need is Where
:
if (objUserRoles.Where(x => x.Role.Role1 == "local").Count() > 0)
或者有<条码>Any,它更有利(而且表现良好,因为在大多数情况下,它赢得了像<条码>Count(<>条码>)这样的全收。
if (objUserRoles.Any(x => x.Role.Role1 == "local"))
请回顾:
if (objUserRoles.Any(x => x.Role.Role1 == "local"))
您在选择一系列<代码>bool。 E.g. 如果您的问询有3项内容,即:代码>false、真实、虚假的,那么你要求的是<代码>false、真实、虚假的<>/code序列,而不仅仅是在真实地点标的。 它希望你重新尝试选择这一系列保ool的真实价值,这意味着你应当使用<代码>。 在而不是Select
的情况下。 然而,由于你们都重新采用了这一条码。 如果和对至少其中一项进行核对,请填写
。 任何代码>,其效率更高。
<http://msdn.microsoft.com/en-us/library/bb534803.aspx” rel=“nofollow”>。
检查情况
if (objUserRoles.Where(x => (x.Role.Role1 == "local")).Count() > 0)
页: 1
<http://msdn.microsoft.com/en-us/library/bb534972.aspx” rel=“nofollow”>Any 推广方法
if (objUserRoles.Any(x => x.Role.Role1 == "local"))
我认为,你想要使用......Where(expr)而不是“Select(expr)。
最好有<条码>。 任何
if (objUserRoles.Where(x => (x.Role.Role1 == "local")).Any())
正如其他人所指出的,Any()或.Where(Count())将给你重新寻找的东西。 页: 1
if (objUserRoles.Select(x => (x.Role.Role1 == "local")).Count() > 0)
......实际上正在创建<代码>。 IE amountable<bool>,其中每个项目都是根据x进行的。 作用:Role1=“当地”
。 您的最终结果总是真实的,因为除非你的切除,否则>.Count(
>>>>s>? 用户名册实际上包含0个元素。
希望澄清对你们来说是有意义的!
您的发言也没有将<条码>objUserRoles至<条码>(boolean)中的任何内容转换成“条码”。
objUserRoles.Select(x => (x.Role.Role1 == "local"))
is a IEnumerable<bool>
with as many elements of your objUserRoles
collection.
i guess what you want to do is described by the following query
if (objUserRoles.Where(x => x.Role.Role1 == "local").Count() > 0)
甚至更好
if (objUserRoles.Any(x => x.Role.Role1 == "local"))
What is the use of default keyword in C#? Is it introduced in C# 3.0 ?
I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...
I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...
I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...
I have two EF entities. One has a property called HouseNumber. The other has two properties, one called StartHouseNumber and one called EndHouseNumber. I want to create a many to many association ...
How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...
Since I cannot order my dictionary, what is the best way of going about taking key value pairs and also maintaing an index?
Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...