Defining an Interface in Visual C Sharp 2010

To define an interface, you use the interface keyword instead of the class or struct keyword .  Inside the interface, you declare methods exactly as in a class or a structure except that you  never specify an access modifier (public, private, or protected), and you replace the method  body with a semicolon .

Here is an example:

interface IComparable 

    int CompareTo(object obj); 
}


well, The Microsoft  .NET Framework documentation recommends that you preface the name of your interfaces with the capital letter I . This convention is the last vestige of Hungarian notation in C# . Incidentally, the System namespace already defines the IComparable interface as shown above .

No comments:

Post a Comment