One of the reasons to introduce generics was to *reduce* the amount of boxing - but another was to allow the writing of generic code. In general boxing is not a huge problem unless you are executing something which boxes in a tight loop or have implemented a mutator interface on a value type (in which case you may update something other than the thing you *think* you are updating).
IComparable is the interface that is used for the concept of *difference* between instances of types - yes if you use a value type in this generic you will see a box, but in your situation is this that significant in real terms (object creation is incredibly cheap in .NET). Is it enough of an issue to go outside of the standard mechanism of indicating a type supports the concept of ordering.
Regards
Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog
?
nntp://news.microsoft.com/microsoft.public.dotnet.languages.csharp/
Mattias Sj?gren wrote:
Jeremy,
but can anyone
suggest a solution for this?
Use a constraint to ensure that the type argument implements
IComparable, and use that for comparison instead.
Mattias
I've tried your suggestion, but it still looks there is a box operation occuring in the CIL, which is what I'm trying to avoid by using the generics over using 'object' as my parameter types.
Any suggestions on how to make this work/other ways around this problem?
Thanks in advance
[microsoft.public.dotnet.languages.csharp]