Query for the smaller nums in an array of ints - CSharp LINQ

CSharp examples for LINQ:where

Description

Query for the smaller nums in an array of ints

Demo Code




using System;/*from  ww w .j av a 2s  . c  o  m*/
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {

        int[] nums = new[] { 5, 7, 1, 4, 9, 3, 0, 2, 6, 8 };
        var smallnumbers = from n in nums   // Generate a sequence.
                           where n <= 3     // Filter it.
                           orderby n        // Sort it.
                           select n;        // Select the desired items (in this case, all of them).
        foreach (var n in smallnumbers)     // Now, execute the query.
        { Console.WriteLine("\t{0}", n); }

    }
}

Result


Related Tutorials