LINQ Restriction Operators example in CSharp

LINQ Restriction Operator

In this LINQ example, we will see how to use where clause in the LINQ. Here we have nums array which is having some integer values. we are writing LINQ for fetching numbers less than 5.


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LinqExamples
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] nums = { 1, 2, 3, 4, 5, 6, 7, 8 };

            var numbersLessThan5=from n in nums 
                                 where n<5 select n;

            foreach (int num in numbersLessThan5)
            {
                Console.WriteLine(num); //output: 1 2 3 4
            }

            Console.ReadLine();
        }
    }

}
Output:

1
2
3
4
Share this post :

Post a Comment

Please give your valuable feedback on this post. You can submit any ASP.NET article here. We will post that article in this website by your name.

 
Support : Ranga Rajesh Kumar
Copyright © 2012. ASP.NET Examples - All Rights Reserved
Site Designed by Ranga Rajesh Kumar