using System;
using System.Linq;
namespace pc.linq02
{
class Program
{
static void Main(string[] args)
{
var nums = Enumerable.Range(1, 20);
var result1 = from n in nums
where n % 2 == 0 && n % 3 == 0
select n;
Array.ForEach(result1.ToArray(), n => Console.Write(n + " "));
Console.WriteLine();
var result2 = from n in nums
where n % 2 == 0
where n % 3 == 0
select n;
Array.ForEach(result2.ToArray(), n => Console.Write(n + " "));
Console.WriteLine();
}
}
}
using System;
using System.Linq;
namespace pc.linq02
{
class Program
{
static void Main(string[] args)
{
var nums = Enumerable.Range(1, 20);
var result1 = nums.Where(n => n % 2 == 0 && n % 3 == 0);
Array.ForEach(result1.ToArray(),
n => Console.Write(n + " "));
Console.WriteLine();
var result2 = nums.Where(n=>n%2 == 0).Where(n=> n %3 == 0);
Array.ForEach(result2.ToArray(),
n => Console.Write(n + " "));
Console.WriteLine();
}
}
}
using System;
using System.Linq;
namespace pc.linq02
{
class Program
{
static void Main(string[] args)
{
var nums = Enumerable.Range(1, 20);
var result1 = nums.Where(n => IsEven(n) &&
IsMultipleOfThree(n));
Array.ForEach(result1.ToArray(),
n => Console.Write(n + " "));
Console.WriteLine();
var result2 = from n in nums
where IsEven(n)
where IsMultipleOfThree(n)
select n;
Array.ForEach(result2.ToArray(), n => Console.Write(n + " "));
Console.WriteLine();
}
static bool IsEven(int i) { return i % 2 == 0; }
static bool
IsMultipleOfThree(int i) { return i % 3 == 0; }
}
}