Skip to content

Instantly share code, notes, and snippets.

@michidk
Created January 28, 2016 22:44
Show Gist options
  • Save michidk/6f076258f38f29be77cb to your computer and use it in GitHub Desktop.
Save michidk/6f076258f38f29be77cb to your computer and use it in GitHub Desktop.
C# is awesome
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