Created
January 28, 2016 22:44
-
-
Save michidk/6f076258f38f29be77cb to your computer and use it in GitHub Desktop.
C# is awesome
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
These 3 pieces of codes, are all returning wether a list/dictionary has elements or not. | |
Normal: | |
int count = 0; | |
foreach (var ep in IPEndPoints) | |
{ | |
if (ep.Value == null) | |
{ | |
count++; | |
} | |
} | |
return count > 0; | |
Predicates/Lamda: | |
IPEndPoints.Count(ep => ep.Value == null) > 0; | |
LINQ: | |
(from ep in IPEndPoints where ep == null select ep).Count() > 0; | |
C# is love. C# is life. <3 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment