How to: Implement Interface

Use this procedure to perform the Implement Interface IntelliSense operation. For more information, see Implement Interface.

To implement an interface in C# with explicit declarations using IntelliSense.

  1. Create a console application. For more information, see Building Console Applications.

  2. Place the cursor after the class Program declaration.

  3. Type : IComparable so the declaration becomes class Program : IComparable.

  4. Activate the smart tag under IComparable. The following two options will appear:

    • Implement interface 'IComparable'.

    • Explicitly implement interface 'IComparable'.

  5. Choose Explicitly implement interface 'IComparable'.

IntelliSense then adds an IComparable.CompareTo method from the IComparable interface to the Program class:

   #region IComparable Members
   int IComparable.CompareTo(object obj)
   {
      throw new Exception("The method or operation is not implemented.");
   }
   #endregion

To implement an interface in C# with implicit declarations using IntelliSense.

  1. Create a console application. For more information, see Building Console Applications.

  2. Place the cursor after the class Program declaration.

  3. Type : IComparable so the declaration becomes class Program : IComparable.

  4. Activate the smart tag under IComparable. The following two options will appear:

    • Implement interface 'IComparable'.

    • Explicitly implement interface 'IComparable'.

  5. Choose Implement interface 'IComparable'.

IntelliSense will then add a CompareTo method from the IComparable interface to the Program class:

   #region IComparable Members
   public int CompareTo(object obj)
   {
      throw new Exception("The method or operation is not implemented.");
   }
   #endregion

To implement an interface in J# using IntelliSense

  1. Create a J# console application.

  2. Open the .jsl file, and under the package statement, add import System.*.

  3. Place the cursor after the class Program statement, and type implements IComparable so the statement becomes class Program implements IComparable.

  4. Activate the SmartTag under IComparable and choose Implement interface System.IComparable stubs.

IntelliSense adds an IComparable.CompareTo method from the IComparable interface to the Program class:

#region IComparable Members
public int IComparable.CompareTo(object obj)
    {
        throw new System.NotImplementedException();
    }
#endregion

See Also

Reference

Implement Interface

Interfaces (C# Programming Guide)

Explicit Interface Implementation (C# Programming Guide)

Other Resources

Automatic Code Generation