Passing references of int and string to an array

  • Thread starter Thread starter Jaga
  • Start date Start date
J

Jaga

How can I pass references of int and string to an array in managed code?

int i = 1;
string s = "1";

object[] a = {ref i, ref s}; //error
a[0] = 2;
a[1] = "2";

(i == 2 && s == "2") should return true now.


Thanks,
Jaga
 
Jaga said:
How can I pass references of int and string to an array in managed
code?

int i = 1;
string s = "1";

object[] a = {ref i, ref s}; //error
a[0] = 2;
a[1] = "2";

(i == 2 && s == "2") should return true now.

You can't do that. You can pass variables by reference to another
method, but you can't make an array element an alias for a variable.
 
Back
Top