Skip to content

C# Feature - Static local functions

Static local functions are local functions that cannot capture variables from the enclosing scope, which makes intent and lifetime rules clearer.

C# 8.0 (2019)

int offset = 5;
int Add(int value) => value + offset;
static int Add(int value, int offset) => value + offset;
  • Use a static local function when capture is accidental or undesirable.
  • Pass required values explicitly as parameters.