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)
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.