+ 17
Can you define and call a method inside another method?
And if you can define and call a method inside another method, then can you still call that method outside that method? E.g static void Main (strings[] args) { int Inside_Method() { //Some code; } } Inside_Method() ;
2 Réponses
+ 4
You can create local functions since C# 7.
https://docs.microsoft.com/en-us/dotnet/csharp/programming-guide/classes-and-structs/local-functions
You can also use lambdas as inner functions. C# even supports closures with the use of local functions or lambdas.
Here's a simple example of an inner / local function:
https://code.sololearn.com/c6FXuurbtp55/?ref=app
+ 2
This may be related, didn't seem to be noting the "callable from outside" part though,
https://stackoverflow.com/questions/18279520/are-there-any-official-ways-to-write-an-immediately-invoked-function-expression