c# expression syntax code example

Example 1: 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;

Example 2: expression function c#

Expression<Func<Student, bool>> isTeenAgerExpr = s => s.Age > 12 && s.Age < 20;

Example 3: c# arrow

// Make a new lambda function
Func<string, string> greet = (name) => $"Hello, {name}!";

// Call it
Console.WriteLine(greet("John"));