Csharp/C Sharp/LINQ/Enumerable.Range

Материал из .Net Framework эксперт
Перейти к: навигация, поиск

Calling the Range Operator

 
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
public class MainClass {
    public static void Main() {
        IEnumerable<int> ints = Enumerable.Range(1, 10);
        foreach (int i in ints)
            Console.WriteLine(i);
    }
}


Use Generation Operators: Range

 
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
public class MainClass {
    public static void Main() {
        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);
        }
    }
}