int counter = 0; Action incrementCounter = () => { counter++; Console.WriteLine($"Counter = {counter}"); }; incrementCounter(); // output: "Counter = 1"
int age = 25; FuncIn this example, GetLocalWithValue can be used to retrieve the value of the "age" local variable inside the lambda expression. Package/Library: System.Linq.Expressions.ageChecker = (thresholdAge) => { bool isOlder = age >= thresholdAge; return isOlder ? "You are old enough." : "You are too young."; }; Console.WriteLine(ageChecker(18)); // output: "You are old enough."