In this article we are going to see the frequently used extension methods in LINQ with the help of Lambda expressions.
Used Namespace
using System;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Web;
Used collection for Demo
public static List<int> GetNumberList()
{
List<int> list = new List<int>();
list.Add(11);
list.Add(22);
list.Add(77);
list.Add(13);
list.Add(17);
list.Add(41);
return list;
}
ALL () LINQ Method
It is used to check whether the entire item in the list matches the specified condition. If one item fails, it returns false.
/// <summary>
/// Just to check whether all element satisfies the given condition or not.
/// Return just TRUE or FALSE.
/// It applies to all the DataType like string,datetime etc and also for custom class.
/// </summary>
public static void LinqIntALL()
{
List<int> list = GetNumberList();
//It returns bool, check whether all the item in the list greather than 13.
bool isAll = list.All(i => i > 13)
//Print
HttpContext.Current.Response.Write("all greather than 13 :" + isAll + "<br/>");
//It returns bool, check whether all the item in the list greather than 10.
isAll = list.All(i => i > 10);
HttpContext.Current.Response.Write("all greather than 10 :" + isAll + "<br/>");
}

ANY () LINQ Method
It is used to check whether any item satisfies the given condition. If one item satisfies then it returns true otherwise false.
/// <summary>
/// Just to check whether all element satisfies the given condition or not.
/// Return just TRUE or FALSE.
/// It applies to all the DataType like string,datetime etc and also for custom class.
/// </summary>
public static void LinqIntANY()
{
List<int> list = GetNumberList();
//It returns bool, Just to check any element is greater than 13.
bool isAll = list.Any(i => i > 13);
//Print
HttpContext.Current.Response.Write("Any greather than 13 :" + isAll + "<br/>");
//It returns bool, Just to check any element is equal to 11.
isAll = list.All(i => i == 10);
HttpContext.Current.Response.Write("Any equal to 11 :" + isAll + "<br/>");
}





Gaurav GuptaPosted Apr 18, 2012, 8:03 AM
can we use linq on dataset???
Shubham SrivastavaPosted Apr 16, 2012, 7:14 PM
sir i want to know can we use xml file through Linq ?