Casting between value types on a class using generics
Posted
by marcelomeikaru
on Stack Overflow
See other posts from Stack Overflow
or by marcelomeikaru
Published on 2010-03-22T13:40:24Z
Indexed on
2010/03/22
13:41 UTC
Read the original article
Hit count: 254
In this section of a function (.NET 2.0):
public void AttachInput(T input, int inIndex) where T : struct { if (input is int) { Inputs.Add(inIndex, (int)input); InputCount++; IsResolved = false; } }
The compiler shows the error "Cannot convert type 'T' to 'int'. So, I used Convert.ToInt32() which worked - but does it box input to an object? Is there a better solution? Thanks
© Stack Overflow or respective owner