This web site uses cookies. By using the site you accept the cookie policy.This message is for compliance with the UK ICO law.

Visual Studio
VS 2005+

Visual Studio Interface Implementation Shortcut

When using interfaces in object-oriented programming, implementing large interfaces can be time consuming. Visual Studio assists in this process by providing a handy shortcut to implementing interfaces using either the implicit or explicit syntax.

Implementing Interfaces Shortcut

Once you have defined an interface, applying it to a new class can be cumbersome. To assist, Visual Studio provides a shortcut operation that adds all of the interface members to a class. The full set of members is contained within a code region that is named to reflect its purpose.

Each interface member generated within the class contains a single line of code that throws a NotImplementedException. This allows you to continue developing the class quickly but highlights problems should a method or property be used before it is implemented.

If the interface being implemented inherits from a base interface, all of the interfaces within the inheritance chain are implemented automatically. Each interface's members are placed in a separate code region.

To use this shortcut, the class declaration is firstly created including the interface name. The interface name is then right-clicked to display a context-sensitive menu. Pointing to "Implement Interface" to expand the submenu provides access to two further options permitting the interface to be implemented using either the implicit or explicit syntax, as shown in the diagram below.

Visual Studio Interface Implementation Menu

16 April 2008