Skip to content

Instantly share code, notes, and snippets.

@tany3
Last active August 29, 2015 13:56
Show Gist options
  • Save tany3/9068557 to your computer and use it in GitHub Desktop.
Save tany3/9068557 to your computer and use it in GitHub Desktop.
C# Tips - カウントを取らなくてい - Use method Any()

カウントを取らなくてい - Use method Any()

あるcollectionが0件であることを知りたいなら、!Any()を使う。

Any()は有無を返す。Count()は個数を返すので、数え上げ処理が動く。

###変更前

if (collection.Count() == 0) { ... } else { ... }

###変更後

if (!collection.Any()) { ... } else { ... }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment