Click here to Skip to main content
15,943,210 members
Home / Discussions / C#
   

C#

 
GeneralRe: Filter HTML Content Before Displaying in WebBrowser Pin
Stephane Rodriguez.24-Sep-02 6:00
Stephane Rodriguez.24-Sep-02 6:00 
GeneralWhen to define interfaces Pin
afronaut23-Sep-02 9:02
afronaut23-Sep-02 9:02 
GeneralRe: When to define interfaces Pin
Stephane Rodriguez.23-Sep-02 9:22
Stephane Rodriguez.23-Sep-02 9:22 
GeneralRe: When to define interfaces Pin
jan larsen24-Sep-02 0:55
jan larsen24-Sep-02 0:55 
GeneralRe: When to define interfaces Pin
John Burton24-Sep-02 3:48
John Burton24-Sep-02 3:48 
GeneralRe: When to define interfaces Pin
leppie24-Sep-02 4:01
leppie24-Sep-02 4:01 
GeneralRe: When to define interfaces Pin
Paul Riley24-Sep-02 4:18
Paul Riley24-Sep-02 4:18 
GeneralRe: When to define interfaces Pin
Paul Riley24-Sep-02 4:12
Paul Riley24-Sep-02 4:12 
The usefulness of interfaces is best described (IMO) in terms of ArrayList.Sort().

An ArrayList can hold an array of pretty much any kind of object. So how does it sort them? What is the easiest way to define a function that could be sorting strings, objects, numbers, and so on?

You can't use ToString() because 10.ToString() == "10", 5.ToString() == "5". Thus 10.ToString() < 5.ToString().

So ArrayList.Sort calls IComparible.CompareTo(object obj) on each object to sort them. Thus if you want to do an ArrayList.Sort then all the objects in the ArrayList must implement the IComparable interface or it will not be able to cast it.

eg.
private class SortableObject : IComparable
{
// normal class code here

	public int CompareTo(object Item)
	{
// Comparison code here
	}
}
This way I can exactly define how I want one SortableObject to compare to another. ArrayList.Sort doesn't give a damn how I compare them, just that I define a method in the exact format public int CompareTo(object Item). It is a contract between my object and ArrayList.Sort saying I'll do the comparison, you do the sort.

Paul
GeneralRe: When to define interfaces Pin
Stephane Rodriguez.24-Sep-02 4:54
Stephane Rodriguez.24-Sep-02 4:54 
GeneralRe: When to define interfaces Pin
Paul Riley24-Sep-02 5:04
Paul Riley24-Sep-02 5:04 
GeneralThread in C# Pin
D Shen23-Sep-02 8:33
D Shen23-Sep-02 8:33 
General.NET ComboBox Item Tags (SetItemData equivalent) Pin
Gaul23-Sep-02 7:40
Gaul23-Sep-02 7:40 
GeneralRe: .NET ComboBox Item Tags (SetItemData equivalent) Pin
leppie23-Sep-02 8:15
leppie23-Sep-02 8:15 
GeneralRe: .NET ComboBox Item Tags (SetItemData equivalent) Pin
Gaul23-Sep-02 9:20
Gaul23-Sep-02 9:20 
GeneralRe: .NET ComboBox Item Tags (SetItemData equivalent) Pin
leppie23-Sep-02 10:18
leppie23-Sep-02 10:18 
GeneralRe: .NET ComboBox Item Tags (SetItemData equivalent) Pin
James T. Johnson23-Sep-02 17:30
James T. Johnson23-Sep-02 17:30 
Generaloutlook add-in event handler doesn't work Pin
derhackler23-Sep-02 4:25
derhackler23-Sep-02 4:25 
GeneralRe: outlook add-in event handler doesn't work Pin
leppie23-Sep-02 5:04
leppie23-Sep-02 5:04 
GeneralRe: outlook add-in event handler doesn't work Pin
derhackler23-Sep-02 5:44
derhackler23-Sep-02 5:44 
GeneralRe: outlook add-in event handler doesn't work Pin
leppie23-Sep-02 5:56
leppie23-Sep-02 5:56 
GeneralRe: outlook add-in event handler doesn't work Pin
derhackler27-Sep-02 5:29
derhackler27-Sep-02 5:29 
GeneralCustom collection and Properties window Pin
Maciej Pirog23-Sep-02 3:43
Maciej Pirog23-Sep-02 3:43 
GeneralRe: Custom collection and Properties window Pin
leppie23-Sep-02 5:51
leppie23-Sep-02 5:51 
GeneralRe: Custom collection and Properties window Pin
Maciej Pirog25-Sep-02 7:53
Maciej Pirog25-Sep-02 7:53 
GeneralRe: Custom collection and Properties window Pin
leppie25-Sep-02 9:18
leppie25-Sep-02 9:18 

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.