This example gives an idea to you how to use where clause in the LINQ. Here we have nums array which 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();
}
}
}
No comments:
Post a Comment