开发者

Linq Detect Non Zero GUIDs in an array?

开发者 https://www.devze.com 2023-02-14 10:55 出处:网络
I am having a brain freeze. I have an array of n GUIDs and either all of them will have complete zeros, or they all won\'t. I am trying to come 开发者_Python百科up with a succinct Linq query that will

I am having a brain freeze. I have an array of n GUIDs and either all of them will have complete zeros, or they all won't. I am trying to come 开发者_Python百科up with a succinct Linq query that will be true or false if they all contain "00000000-0000-0000-0000-000000000000" but can't, so here I am. Can anyone help?

Thanks.


Like this:

if (arr.Any(g => g != Guid.Empty))


How about:

IEnumerable<Guid> guids = ...    
bool allZeros = guids.All(guid => guid == Guid.Empty);


You can use:

bool allZero = array.All(guid => guid == Guid.Empty);


What about checking for Guid.Empty? It is equal to a Guid with all zeroes.

0

精彩评论

暂无评论...
验证码 换一张
取 消