Skip to content

Instantly share code, notes, and snippets.

@Koki-Shimizu
Created August 23, 2013 15:17
Show Gist options
  • Save Koki-Shimizu/6320489 to your computer and use it in GitHub Desktop.
Save Koki-Shimizu/6320489 to your computer and use it in GitHub Desktop.
LINQ Sample. You can write light and clean code using LINQ.
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace LINQsample01
{
class Program
{
static void Main(string[] args)
{
{
var nums = Enumerable.Range(0, 100);
int counter = 0;
foreach (var item in nums)
{
if (item % 2 == 0)
{
counter++;
}
}
Debug.WriteLine("count is {0}", counter);
}
{
var count = Enumerable.Range(0, 100).Count(num => num % 2 == 0);
Debug.WriteLine("count is {0}", count);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment