linq Range

linq Range
This sample uses Range to generate a sequence of numbers from 100 to 149 that is used to find which numbers in that range are odd and even.
 public static void Range()
        {
            var numbers = from n in Enumerable.Range(100, 50)
                          select new { Number = n, OddEven = n % 2 == 1 ? "odd" : "even" };

            foreach (var n in numbers)
            {
                Console.WriteLine("The number {0} is {1}.", n.Number, n.OddEven);
            }

        }
Output


linq Range linq Range Reviewed by Bhaumik Patel on 8:31 PM Rating: 5