+ 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() ;

1st Jul 2020, 2:16 PM
Vachila64☕
Vachila64☕ - avatar
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
28th Jul 2020, 3:07 AM
David Carroll
David Carroll - avatar
+ 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
1st Jul 2020, 3:26 PM
Ipang