C# Feature - Static local functions
Overview
Section titled “Overview”Static local functions are local functions that cannot capture variables from the enclosing scope, which makes intent and lifetime rules clearer.
Introduced In
Section titled “Introduced In”C# 8.0 (2019)
Before
Section titled “Before”int offset = 5;int Add(int value) => value + offset;static int Add(int value, int offset) => value + offset;Gotchas & Best Practices
Section titled “Gotchas & Best Practices”- Use a static local function when capture is accidental or undesirable.
- Pass required values explicitly as parameters.