Static local functions are designed to be independent of the state of the enclosing scope. Therefore, if ReSharper detects a local function that does not use any variables from the enclosing scope, it suggests making such function static.
This way ReSharper infers the intended use of the function and makes sure that this intent is clearly visible to those who will read or modify the code later.
classTest{voidFoo(){
Console.WriteLine(LocalFunction1("test "));// Can be made static because no local variables are capturedstringLocalFunction1(string str)=> str.Trim(' ');conststring test ="test ";
Console.WriteLine(LocalFunction2());// Cannot be made static because the variable 'test' is capturedstringLocalFunction2()=> test.Trim(' ');}}
Our website uses some cookies and records your IP address for the purposes of accessibility, security, and managing your access to the telecommunication network. You can disable data collection and cookies by changing your browser settings, but it may affect how this website functions. Learn more.
With your consent, JetBrains may also use cookies and your IP address to collect individual statistics and provide you with personalized offers and ads subject to the Privacy Notice and the Terms of Use. JetBrains may use third-party services for this purpose. You can adjust or withdraw your consent at any time by visiting the Opt-Out page.