Created
August 23, 2013 15:17
-
-
Save Koki-Shimizu/6320489 to your computer and use it in GitHub Desktop.
LINQ Sample.
You can write light and clean code using LINQ.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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