how to create function inside another function in c#,is it possible?

c#, methods

Solution

It is most certainly possible.

You can create delegates, which are functions, inside other methods. This works in C# 2.0:

public void OuterMethod() {
    someControl.SomeEvent += delegate(int p1, string p2) {
        // this code is inside an anonymous delegate
    }
}

And this works in newer versions with lambdas:

public void OuterMethod() {
    Func<int, string, string> myFunc = (int p1, string p2) => p2.Substring(p1)
}

Problem

Is it possible to create a function inside another function in C#? If so, how can this be done?

Original source

Related problems