Click here to Skip to main content
16,005,467 members
Home / Discussions / C#
   

C#

 
GeneralRe: UnhandledExceptionEventHandler Pin
Nick Parker29-May-02 5:08
protectorNick Parker29-May-02 5:08 
QuestionCan I do multiple selection onDatagrid in WinForms? Pin
28-May-02 5:34
suss28-May-02 5:34 
Generalcreate xml for collection class Pin
sharon28-May-02 1:58
sharon28-May-02 1:58 
GeneralRe: create xml for collection class Pin
James T. Johnson28-May-02 8:33
James T. Johnson28-May-02 8:33 
GeneralRe: create xml for collection class Pin
sharon28-May-02 19:15
sharon28-May-02 19:15 
QuestionWhat the ¤#& is the use of Interfaces!!! Pin
Rickard Andersson2028-May-02 1:28
Rickard Andersson2028-May-02 1:28 
AnswerRe: What the ¤#& is the use of Interfaces!!! Pin
Nish Nishant28-May-02 4:02
sitebuilderNish Nishant28-May-02 4:02 
AnswerRe: What the ¤#& is the use of Interfaces!!! Pin
James T. Johnson28-May-02 8:27
James T. Johnson28-May-02 8:27 
An interface defines one set of related methods that can be implemented by any class to perfom some task.

Take the IComparable interface as an example. It is very simple but what it does means a lot. In this case IComparable has a single method, CompareTo, which compares the object with one that is passed in and returns an int debending on how it compares. Negative values means the instance is less than the one passed in, 0 means they are equal, and positive means the instance is greater than the one passed in.

The reason this is an interface is simple; it is easy to get an interface vs finding out of a class implements a method; then have to worry about what accessability modifiers (public/private/etc) it has. Some objects don't make sense to have a less-than/equal/greater-than operators so making it a method of Object is useless in those cases (for example, one Point is no less than or greater than another; only equal or not equal).

To find out what the required implementation of IComparable is you refer to the contract, in this case that is the MSDN entry for IComparable.

To get an instance of the interface, either cast to it or use the as keyword.

IComparable ic = (IComparable) myString; or IComparable ic = myString as IComparable.

I show a couple uses of interfaces in my article "Using reflection to extend .NET programs", though it discusses reflection more than interfaces you can see how I use an interface to load classes at runtime without needing to know about the class itself.

James

Simplicity Rules!
GeneralRe: What the ¤#& is the use of Interfaces!!! Pin
Nish Nishant28-May-02 14:47
sitebuilderNish Nishant28-May-02 14:47 
GeneralRe: What the ¤#& is the use of Interfaces!!! Pin
James T. Johnson28-May-02 14:53
James T. Johnson28-May-02 14:53 
GeneralScaling a transparent 256 colors gif or png with GDI+ Pin
27-May-02 22:33
suss27-May-02 22:33 
GeneralRe: Scaling a transparent 256 colors gif or png with GDI+ Pin
James T. Johnson28-May-02 8:29
James T. Johnson28-May-02 8:29 
GeneralRe: Scaling a transparent 256 colors gif or png with GDI+ Pin
Todd Smith30-May-02 7:11
Todd Smith30-May-02 7:11 
QuestionHow can I use the libraries on runtime? Pin
Vu Truong27-May-02 22:10
Vu Truong27-May-02 22:10 
AnswerRe: How can I use the libraries on runtime? Pin
Nish Nishant28-May-02 1:07
sitebuilderNish Nishant28-May-02 1:07 
GeneralConverting Windows Forms to Web Forms using C# Pin
27-May-02 18:22
suss27-May-02 18:22 
GeneralVersioning Pin
27-May-02 18:05
suss27-May-02 18:05 
GeneralRe: Versioning Pin
James T. Johnson28-May-02 8:36
James T. Johnson28-May-02 8:36 
GeneralRe: Versioning Pin
29-May-02 9:55
suss29-May-02 9:55 
GeneralCalling default mail client...... Pin
Pranoti27-May-02 7:35
Pranoti27-May-02 7:35 
GeneralRe: Calling default mail client...... Pin
Rocky Moore27-May-02 8:46
Rocky Moore27-May-02 8:46 
GeneralUsing OCX controls in .NET Pin
JerzyPeter27-May-02 5:50
JerzyPeter27-May-02 5:50 
GeneralTextBox text color Pin
Paddy26-May-02 19:30
Paddy26-May-02 19:30 
GeneralRe: TextBox text color Pin
Nick Parker26-May-02 19:33
protectorNick Parker26-May-02 19:33 
GeneralRe: TextBox text color Pin
Paddy26-May-02 19:47
Paddy26-May-02 19:47 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.