I would like to have a method where the parameter could be Int32
or Single
:
void myMethod( ref object x )
{
//...CodeHere
}
Since C# does not allow me to pass a specialization of object when using out
or ref
, the solution I found claimed that assigning the variable to a variable of the type object
would be enough:
Single s = 1.0F;
object o = s;
myMethod( ref o );
That didn't work. According to the Microsoft documentation I looked at, o
should be a pointer to s
. The sources I looked at state that assigning non-primitive types generate a reference and not a new
instance.
Is it possible to have a method where I can pass Single
or Int32
or any other type that is a specialization of object
?