Answer: Local functions allows us to define a function inside the scope/block of another function. It allows to declare methods and types in block scope just like variables. The concept is very similar to Closure.
e.g.
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
void AddNumbersUsingLocalFunction(int a=10, int b=20)
{
Console.WriteLine("Using Local Function : Sum is {0}", a+b);
}
AddNumbersUsingLocalFunction(16);
Console.ReadKey();
}
}
}
As can be figure out that, inside the Main method we have implemented the AddNumbersUsingLocalFunction function. Hence it's scope is bounded inside that block only.
Asked In: Many Interviews |
Alert Moderator