Skip to main content

Declare Interface

  • 2 minutes to read
In This Article

Generates an interface for the current type reference. Places the cursor on the generated interface contents and drops a marker onto the initial interface reference.

Declare Interface also declares interface members called from the initial code, if you call the code provider for an interface reference within a method or property accessor.

#Availability

From the context menus or via shortcuts:

  • when the edit cursor or caret is on a type reference whose name begins with I. For instance, IMyInterface.

Note

The type name must begin with letter I, otherwise the code provider is unavailable.

#Example

class TestClass
{
    private void TestMethod()
    {IMyInterface objVar = new ClassA("ClassName", 15);
        objVar.DoWork(25, true);
        objVar.intValue = 64;
    }
}
Public Class TestClass
    Private Sub TestMethod()
        Dim objVar As IMyInterface = New ClassA("ClassName", 15)
        objVar.DoWork(25, True)
        objVar.intValue = 64
    End Sub
End Class

Result:

public interface IMyInterface
{
    int intValue { get; set; }

    void DoWork(int param1, bool param2);

}
class TestClass
{
    private void TestMethod()
    {
        IMyInterface objVar = new ClassA("ClassName", 15);
        objVar.DoWork(25, true);
        objVar.intValue = 64;
    }
}
Public Interface IMyInterface
    Property intValue() As Integer
    Sub DoWork(ByVal param1 As Integer, ByVal param2 As Boolean)

End Interface
Public Class TestClass
    Private Sub TestMethod()
        Dim objVar As IMyInterface = New ClassA("ClassName", 15)
        objVar.DoWork(25, True)
        objVar.intValue = 64
    End Sub
End Class