Skip to content

Instantly share code, notes, and snippets.

@kawakawa
Created September 11, 2012 13:05
Show Gist options
  • Save kawakawa/3698315 to your computer and use it in GitHub Desktop.
Save kawakawa/3698315 to your computer and use it in GitHub Desktop.
LINQ Sample1
int[] array = { 1, 10, 30, 40, 50, 70, 80, 90 };
//50以上の値の数(for)
int count = 0;
for (int i = 0; i < array.Length; i++)
{
if (array[i] >= 50)
{
count++;
}
}
Console.WriteLine(count);
//50以上の値の数(LINQ)
int CountLinq = (from n in array
where n >= 50
select n).Count();
Console.WriteLine(CountLinq);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment