Declare Delegate

Declares a delegate type for the current reference.

Availability

From the context menus or via shortcuts:

  • when the edit cursor or caret is on a reference to an undeclared delegate type.

Example

class TestClass
{
    static void Test()
    {
        int x = 1;SimpleAction increment = delegate { x++; };
        increment();
        increment();
    }
}
Public Class TestClass
    Sub Test()
        Dim x As Integer = 1
        Dim increment As SimpleAction = Function() x + 1
        increment()
        increment()
    End Sub
End Class

Result:

public delegate void SimpleAction();
class TestClass
{
    static void Test()
    {
        int x = 1;SimpleAction increment = delegate { x++; };
        increment();
        increment();
    }
}
Public Delegate Function SimpleAction() As Integer
Public Class TestClass
    Sub Test()
        Dim x As Integer = 1
        Dim increment As SimpleAction = Function() x + 1
        increment()
        increment()
    End Sub
End Class