Skip to content

Instantly share code, notes, and snippets.

@tany3
Created February 27, 2014 07:05
Show Gist options
  • Save tany3/9245669 to your computer and use it in GitHub Desktop.
Save tany3/9245669 to your computer and use it in GitHub Desktop.
カウントを取らなくてい - 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