expression function c#
public class Student
{
public int StudentID { get; set; }
public string StudentName { get; set; }
public int Age { get; set; }
}
Func<Student, bool> isTeenAger = s => s.Age > 12 && s.Age < 20;
expression function c#
public class Student
{
public int StudentID { get; set; }
public string StudentName { get; set; }
public int Age { get; set; }
}
Func<Student, bool> isTeenAger = s => s.Age > 12 && s.Age < 20;
c# lambdas
//Lambdas are just short handed anonymous method or functions usally
//for use in passing to other methods or functions to call such as a sort.
//Example:
//The Lambda used here after the =s
Action ExampleContainerForDelagate = ()=>
{/*Do something such as this example*/
Console.WriteLine("Hello world");
};
//has been shorted from this anonymous delegate or method.
Action ExampleContainerForDelagate = delegate () { Console.WriteLine("Hello world"); };
//And this full (named) method signature method passing
Action ExampleContainerForDelagate = ExampleMethod;
void ExampleMethod()
{ Console.WriteLine("Hello world"); }
//usage example
List<int> ExampleList = new List(){1,3,0};
ExampleList.Sort((x,y)=>{return x - y; });
//The Sort will sort based on the return values from the Lambda passed.
//a negative will be seen as a smaller than the next number
//a 0 will be seen as equal
//and a positive will be seen as bigger than the next number
//by switching x and y postion in the 'return x - y;' you will effectively
//change the sort to descending order. This is there for useful for sorting
//based on needs or where it is not obvious how to sort.
expression function c#
Expression<Func<Student, bool>> isTeenAgerExpr = s => s.Age > 12 && s.Age < 20;
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us