Invoke the Lambda Expression
As you have seen in the previous section, the lambda expression is a shorter way of representing an anonymous method. An anonymous method can be created using delegate, which can be invoked in the same way as a function. So, a lambda expression can be assigned to a compatible delegate type and be invoked like a delegate.
Consider the following lambda expression that determines whether a student is a teenager or not.
s => s.age > 12 && s.age < 20;To invoke the above lambda expression, first of all create a delegate that accepts a paramter of Student type, returns a boolean value and then assigns the lambda expression, shown above, to the delegate type as shown below. Then the delegate type variable with () operator must be used to invoke it.
delegate bool isTeenAger(Student student);
isTeenAger isStudentTeen = s => s.age > 12 && s.age < 20;
Student std = new Student() { age = 21 };
isStudentTeen(std);// returns falseInstead of creating a custom delegate type (isTeenAger) as shown above, you can use built-in delegate types Func<> and Action<>.
Func Delegate type
Use the Func<> delegate when you want to return something from a lambda expression. The last parameter type in a Func<> delegate is the return type and rest are input parameters. Visit Func delegate section of C# tutorials to know more about it.
Consider the following lambda expression to find out whether a student is a teenager or not.
Func<Student, bool> isStudentTeenAger = s => s.age > 12 && s.age < 20;
Student std = new Student() { age = 21 };
bool isTeen = isStudentTeenAger(std);// returns falseIn the above example, the Func delegate expects the first input parameter to be of Student type and the return type to be boolean. The lambda expression s => s.age > 12 && s.age < 20 satisfies the Func<Student, bool> delegate requirement, as shown below:

The Func<> delegate shown above, would turn out to be a function as shown below.
bool isStudentTeenAger(Student s)
{
return s.Age > 12 && s.Age < 20;
}Action delegate type
Unlike the Func delegate, an Action delegate can only have input parameters. Use the Action delegate type when you don't need to return any value from lambda expression.
Action<Student> PrintStudentDetail = s => Console.WriteLine("Name: {0}, Age: {1} ", s.StudentName, s.Age);
<span className="userclass">Student</span> std = <span className="kwrd">new</span> <span className="userclass">Student</span>(){ StudentName = <span className="str">"Bill"</span>, Age=21};
PrintStudentDetail(std);You can pass a lambda expression of Func or Action delegate type to a LINQ query. Enumerable static class for LINQ includes Where extension method for IEnumerable<T> that accepts a predicate of Func<TSource,bool>. So, the Where() extension method for IEnumerable<Student> collection is required to pass Func<Student,bool>, as shown below:

So now, you can pass the lambda expression assigned to the Func delegate to the Where() extension method in the method syntax as shown below:
IList<Student> studentList = new List<Student>(){...};
<span className="userclass">Func</span><<span className="userclass">Student</span>, <span className="kwrd">bool</span>> isStudentTeenAger = s => s.age > 12 && s.age < 20;
var teenStudents = studentList.Where(isStudentTeenAger).ToList<Student>();IList<Student> studentList = new List<Student>(){...};
Func<Student, bool> isStudentTeenAger = s => s.age > 12 && s.age < 20;
var teenStudents = from s in studentList
where isStudentTeenAger(s)
select s;You can follow the same method in VB.Net to pass Func delegate.