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.
精彩评论