This documentation is archived and is not being maintained.

Implementing Interfaces

Visual Studio .NET 2003

To implement an interface, you must implement every member of the interface in your class, which can be a tedious task for interfaces that have numerous members.

IntelliSense provides an option to help you implement your interfaces quickly while working in the Code Editor. After you type the name of an interface in a class declaration, IntelliSense prompts you to press the TAB key to automatically implement method stubs for the interface, as shown in the following screen shot.

Example

This example shows how to use IntelliSense to quickly implement stubs for an interface. In this example, you will create a class named MyClass that implements the IEnumerator interface.

To implement an interface

  1. Create a C# Windows application.
  2. In the Code Editor, create a class named MyClass that implements the IEnumerator interface by typing out the following statement:
    public class MyClass : IEnumerator
    

    A ToolTip appears, prompting you to press the TAB key to automatically implement stubs for IEnumerator.

    Note   You can avoid automatically implementing the interface by pressing ESC or by continuing to type.
  3. Press the TAB key. IntelliSense generates all the code needed to implement the IEnumerator interface. It also places the generated method stubs in collapsed named regions and then moves the cursor to the line under the closing brace of your class.

    If you expand the collapsed region in MyClass, your interface implementation will look similar to the following example:

    public class MyClass : IEnumerator
    {
       #region IEnumerator Members
    
       public void Reset()
       {
          // TODO:  Add MyClass.Reset implementation
       }
    
       public object Current
       {
          get
          {
             // TODO:  Add MyClass.Current getter implementation
             return null;
          }
       }
    
       public bool MoveNext()
       {
          // TODO:  Add MyClass.MoveNext implementation
          return false;
       }
    
       #endregion
    }
    
    Note   If you want to implement multiple interfaces, add additional interfaces to the class declaration in the Code Editor. The IntelliSense ToolTip that provides you the option for automatic interface implementation will appear for each interface.

See Also

Visual C# IntelliSense

Show: