开发者

Linq Detect Non Zero GUIDs in an array?

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜