CKTIS / C#
=>: practical reference
=>: practical reference: The => operator creates a lambda expression or separates a pattern from its result in a switch expression.
Version: C# operator reference; verified against C# 14
Syntax
parameters => expressionThe => operator creates a lambda expression or separates a pattern from its result in a switch expression.
Use it for short functions passed as a delegate or expression tree.
A lambda captures variables rather than snapshots and can extend object lifetimes.
Parameter and result types need context; an async lambda can convert to a delegate returning Task, Task, or another suitable task-like type, and also to a void-returning delegate, which gives it async void semantics.
The complete program actually uses =>; its exact expected stdout is 25.
Examples
using System;
using System.Linq;
using System.Threading.Tasks;
Func<int, int> square = value => value * value; Console.WriteLine(square(5));
Result
25
The complete program actually uses `=>`; its exact expected stdout is `25`.