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.
Create a console application.
Place the cursor after the class Program declaration.
Type : IComparable so the declaration becomes class Program : IComparable.
Activate the smart tag under IComparable. The following two options will appear:
Implement interface 'IComparable'.
Explicitly implement interface 'IComparable'.
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.
Create a console application.
Place the cursor after the class Program declaration.
Type : IComparable so the declaration becomes class Program : IComparable.
Activate the smart tag under IComparable. The following two options will appear:
Implement interface 'IComparable'.
Explicitly implement interface 'IComparable'.
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
See Also
Reference
Interfaces (C# Programming Guide)
Explicit Interface Implementation (C# Programming Guide)