J
Jazper Manto
hi
i want to have a method with a ref object parameter so that i can pass any
object by reference and write output in it like code below. the problem is
it does not work in c# like i coded it. i do NOT want to use overloads!!! is
it possible? if yes, how?
thanx jazper
--- CODE ---
public void foo(ref object o)
{
if( o is int) ((int)o) = 1;
else if( o is double) ((double)o) = 3.5;
else if( o is string) ((string)o) = "test";
else throw new Exception("type not recognized!");
}
public void callfoo()
{
int i = 0;
double d = 0.0;
string s = string.Empty;
foo(ref (object)i);
foo(ref (object)d);
foo(ref (object)s);
}
i want to have a method with a ref object parameter so that i can pass any
object by reference and write output in it like code below. the problem is
it does not work in c# like i coded it. i do NOT want to use overloads!!! is
it possible? if yes, how?
thanx jazper
--- CODE ---
public void foo(ref object o)
{
if( o is int) ((int)o) = 1;
else if( o is double) ((double)o) = 3.5;
else if( o is string) ((string)o) = "test";
else throw new Exception("type not recognized!");
}
public void callfoo()
{
int i = 0;
double d = 0.0;
string s = string.Empty;
foo(ref (object)i);
foo(ref (object)d);
foo(ref (object)s);
}