| 1) How do I initialize a T value without doing boxing/unboxing ?
| Not possible, must use T value = (T)(Object)cons tant value
| even if I know that the constant value if of type T
Boxes the value! Remember (object) says to box value types!
You have two options on initializing T values without boxing:
1. default(T)
2. Parameterized constructor
NOTE: The reflection trick I showed earlier will box values.
| 2) How do I compare two T values without boxing/unboxing ?
Constrain T by IComparable<T>
http://msdn2.microsoft.com/en-us/library/4d7sx9hd.aspx
NOTE: System.ICompara ble<T> is different then System.ICompara ble!
In the case of simple equality, I would recommend constraining T by
IEquatable<T>.
http://msdn2.microsoft.com/en-us/lib...US,VS.80).aspx
--
Hope this helps
Jay [MVP - Outlook]
..NET Application Architect, Enthusiast, & Evangelist
T.S. Bradley -
http://www.tsbradley.net
"Luc Vaillant" <Lu*********@di scussions.micro soft.com> wrote in message
news:33******** *************** ***********@mic rosoft.com...
| Is that an answer ?
|
| I'm not writing a keyboard typing application, and I DO CARE ABOUT SPEED.
|
| > If speed is that much of an issue, then don't write code that invokes so
| > much boxing
|
| That's why I wanted to use Generics...
|
| > The example that you give doesn't really seem to fit the
| > generic programming model due to the possible differences in behaviour
| > required by the different types that may be used
|
| The example I gave was just to demonstrate the initialization issue. It
was
| not a real use case...
| Same remark about the 'Generics limitation' post I sent today. The example
| is to desmonstrate the != operator issue with generics, and this is not my
| real program...
|
| Why don't you try to answer my questions instead of explaining me that
most
| programs don't need speed, and that my examples don't "really seem to fit
the
| generic programming model".
|
| My questions are simple:
|
| 1) How do I initialize a T value without doing boxing/unboxing ?
|
| The answer is:
| Not possible, must use T value = (T)(Object)cons tant value
| even if I know that the constant value if of type T
|
| 2) How do I compare two T values without boxing/unboxing ?
|
| The answer is:
| Not possible from the answers I got in this post
|
|
| Regards
| Luc
|
|
| "Joanna Carter [TeamB]" wrote:
|
| > "Luc Vaillant" <Lu*********@di scussions.micro soft.com> a écrit dans le
| > message de news:
7F************* *************** **...icrosof t.com...
| >
| > | This will also box Char.MinValue into Object
| >
| > I won't deny that :-)
| >
| > Tell me, what are you doing that requires such super-optimised code ?
Most
| > business applications are only really as fast as the person typing at
the
| > keyboard.
| >
| > If speed is that much of an issue, then don't write code that invokes so
| > much boxing. The example that you give doesn't really seem to fit the
| > generic programming model due to the possible differences in behaviour
| > required by the different types that may be used. In which case, I would
| > tend to look elsewhere for a solution; generics are only really useful
when
| > the behaviour for *all* anticipated types is *identical*.
| >
| > Joanna
| >
| > --
| > Joanna Carter [TeamB]
| > Consultant Software Engineer
| >
| >
| >