The requested page is not available for the requested platform. You are viewing the content for Default platform.

Name Anonymous Method (C#)

Converts an anonymous method to an instance method.

Availability

Available from the context menu or via shortcuts:

  • when the caret is on the delegate keyword within an anonymous method declaration. The method shouldn't use local variables.

Example

public class TestClass 
{
    private void TestMethod() 
    {
        Func<int, int, int> adder1 = delegate(int x, int y) {
            return x + y;
        };
    }
}

Result:

public class TestClass 
{
    private static int Add(int x, int y)
    {
        return x + y;
    }
    private void TestMethod() 
    {
        Func<int, int, int> adder1 = Add;
    }
}

Animation

rsNameAnonymousMethod