As already mentioned, you will need the Count () extension method. However, for their calculation, it will be necessary to sort through all the elements of the collection (in the general case). If the number of elements can be large, and you only need to check that this number is 1, you can use the Take () method:
else if (result.Take(2).Count() == 1)
This does not look so good, but will prevent iteration over the entire result.
source
share