Tricky boxing question

  • Thread starter Thread starter Chris Capel
  • Start date Start date
C

Chris Capel

I want to do something along the lines of this:

class someclass {
static void Main() {
int i = 5;
int j = 3;
changevalue(ref i, j);
Console.WriteLine(i.ToString()); //I want this to output 3
}
//it's important that this parameter is an object, and not an int or
something
static void changevalue(ref object i, object j) {
i = j
}
}

I'd like this to work for any type, not just ints. Is there any way to
accomplish something like this?

Chris
 
Hi Subash,
I don't thing this is exactly what Chris wants to do. a and b are declared
as a references to object. I think Chris wants to have changevalue method
regardles of the type of variables. It is kind a silly to keep value types
in boxing state. At least it is error prone.

B\rgds
100
 
Back
Top