Skip to content

Instantly share code, notes, and snippets.

@YuvalItzchakov
Created December 13, 2015 15:27
Show Gist options
  • Save YuvalItzchakov/5b728c1849dfa871ceb6 to your computer and use it in GitHub Desktop.
Save YuvalItzchakov/5b728c1849dfa871ceb6 to your computer and use it in GitHub Desktop.
List<int> collection = GetCollection();
if ((collection?.Any(x => x > 5))
{
// Is the collection null, or isn't there any element?
}
else
{
// I want to access the list here, need to add a null check:
if (collection != null)
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment