C# Feature – Expression-bodied members
Overview
Section titled “Overview”Use =>
to define concise members (properties, methods, constructors, finalizers) when a single expression suffices.
Introduced In
Section titled “Introduced In”C# 6–7 (expanded over versions)
Before
Section titled “Before”int Inc(int x) { return x + 1; }
int Inc(int x) => x + 1;
Annotated Example
Section titled “Annotated Example”public string Name { get; }public override string ToString() => Name;
Gotchas & Best Practices
Section titled “Gotchas & Best Practices”- Keep bodies simple; use block bodies for complex logic.
Related Features
Section titled “Related Features”Version Notes
Section titled “Version Notes”- Expanded across C# 6 and 7 to more member kinds.