Taking the use of generics to the next level, we then get developers into the idea of using the Generic interfaces - take IComparable
Normally, you would implement IComparable with a CompareTo(object) where you would cast the object into the type you are comparing with. With IComparable
Theoretically, the idea seems to work pretty well but you would notice that a couple of the .NET framework classes just won't play along. Take the Array.Sort method, for instance - it will just complain about not finding an implementation of the non-generic IComparable. The same applies to the Array.Sort
...so yet again, we're stuck with having to implement non-generic interfaces till a 'truly generic' version of Array.Sort
(Coming up soon: Extension methods to get around this issue)
No comments:
Post a Comment