Azurewrath

Hi all,

If I implement a method like CompareTo but don't write the : IComparable after the class name, what would be the consequences Would that method still be effective, but only the class wouldn't get the benefits of IComparable implementers (like extension methods, etc)




Thanks,
Aw


Re: Visual C# Language Interface Question

Nullable

Say you have a list (ArrayList or Generic) of your class objects and you want to sort. If you have implemented IComparable then you can directly call list.Sort() and it will sort using IComparable.CompareTo() method implementation. If you just had a method CompareTo without implementing IComparable, the Sort() method won't know how to order your item or which method to call to compare it with another.





Re: Visual C# Language Interface Question

Azurewrath

Thanks alot.

So it will not scan for my CompareTo method inside my class which isn't written so :

public class Vector3 : IComparable




Thanks,
Aw




Re: Visual C# Language Interface Question

Nullable

The built in Sort Method will only look for IComparable.CompareTo() implementation.

Cheers





Re: Visual C# Language Interface Question

Azurewrath

Thanks man!




Aw