In JavaScript, one can write:
var variableWithALongName = 4;
var amount = 5;
((a) => {
amount += a * (a + 1);
})(variableWithALongName);
console.log(amount); // 25
The function involved here is an anonymous function, used only in this part of the code, which does not return any value, it just modifies something (it just does some stuff). Instead of that simple function, there could be a more complicated function which takes some complicated arguments and uses them many times.
Is there anything like that in C#?
I am aware of an over 10 years old similar question and I see one of its answers seems to be more useful and more about actual anonymous functions than the official documentation. However, I am interested in functions that don't return any value. The closest to the above JS code I can currently think of is this (e.g. using Unity's Debug.Log):
int variableWithALongName = 4;
int amount = 5;
new Func<int, bool>((a) => {
amount += a * (a + 1);
return true;
})(variableWithALongName);
Debug.Log(amount); // 25
However, that function still returns something and, although it is just an (arbitrary) bool value that is never used, I wonder if even that can be avoided, to make that C# code more similar to the JS one.
Also, just to be clear, by anonymous function I think of a function that doesn't take up any name, i.e. that doesn't need something like someName = ...
followed by someName(parameters)
somewhere else in code. I'm pointing this out because I have noticed that some of these are also being called anonymous functions for reasons unknown to me.