J
Jasper Kent
I've just been playing around with the Visual Studio 2005 preview, and
obviously one of the first things I did was try to write a Max template.
I can write:
public static T Max<T> (T l,T r) where T :
System.Collections.Generic.IComparable <T>
{
return l.CompareTo (r) > 0 ? l : r;
}
But I can't find a way to do the comparison with operator < (because
operators are static and therefore cannot be defined in interfaces). Is it
possible to reference operators (or any static methods) on template
parameter objects?
Also, are there things like Max and Min already defined as templates in the
..NET library?
As you may have guessed, I come from a C++ background.
Thanks,
Jasper Kent.
obviously one of the first things I did was try to write a Max template.
I can write:
public static T Max<T> (T l,T r) where T :
System.Collections.Generic.IComparable <T>
{
return l.CompareTo (r) > 0 ? l : r;
}
But I can't find a way to do the comparison with operator < (because
operators are static and therefore cannot be defined in interfaces). Is it
possible to reference operators (or any static methods) on template
parameter objects?
Also, are there things like Max and Min already defined as templates in the
..NET library?
As you may have guessed, I come from a C++ background.
Thanks,
Jasper Kent.