Linq Query:
Output:
//Range var evenOddNumbers = from n in Enumerable.Range(1,30) select new { Number=n, IsEven = (n % 2 ==0) ? "Even": "Odd" }; foreach (var t in evenOddNumbers) { Console.WriteLine(" Number: {0} IsEven : {1}", t.Number, t.IsEven); }
Output:
Number: 1 IsEven : Odd
Number: 2 IsEven : Even
Number: 3 IsEven : Odd
Number: 4 IsEven : Even
Number: 5 IsEven : Odd
Number: 6 IsEven : Even
Number: 7 IsEven : Odd
Number: 8 IsEven : Even
Number: 9 IsEven : Odd
Number: 10 IsEven : Even
Number: 11 IsEven : Odd
Number: 12 IsEven : Even
Number: 13 IsEven : Odd
Number: 14 IsEven : Even
Number: 15 IsEven : Odd
Number: 16 IsEven : Even
Number: 17 IsEven : Odd
Number: 18 IsEven : Even
Number: 19 IsEven : Odd
Number: 20 IsEven : Even
Number: 21 IsEven : Odd
Number: 22 IsEven : Even
Number: 23 IsEven : Odd
Number: 24 IsEven : Even
Number: 25 IsEven : Odd
Number: 26 IsEven : Even
Number: 27 IsEven : Odd
Number: 28 IsEven : Even
Number: 29 IsEven : Odd
Number: 30 IsEven : Even
0 comments:
Post a Comment