Lambda Query

What is a Lambda Expression?

            A lambda expression is an anonymous function. It allows to write a method in the same place you are going to use it.
 syntax : Parameters => Executed code.

Basic Lambda Expression

1)Where

  List<int> mark = new List<int>{90, 71, 82, 93, 75, 82 };
  var result= mark.Where(n => n > 80);
  Console.WriteLine("Values greater than 80 are");  
  foreach(val item in result)
      Console.WriteLine("{0}", item ); 
     }
// Outputs: 
// Value greater than 80 are
// 90
// 82 
// 93
// 82

2)Count()

  int result= mark.Where(n => n > 80).Count() ;
  Console.WriteLine("{0} markare greater than 80", result);
 // Outputs: 
 // 4 mark are greater than 80
 

3)Sum()

 int result= mark.Where(n => n > 80).Count() ;
 Console.WriteLine("{0} markare greater than 80", result);   
// Outputs: 
// Sum of mark greater than 80 are
// 347 

Comments