You can if you want to use the undocumented keywords __arglist and __refvalue in C #.
Caution: Undocumented features may be changed in future versions of C #. Use these keywords only if necessary, realizing that your code may stop working if Microsoft changes its behavior in the next version.
For example, the following program passes three int variables by reference to the GetRandomValues method. It prints 2, 1, and 4, demonstrating that the variables have been successfully changed.
static void Main() { int x = 0, y = 0, z = 0; GetRandomValues(__arglist(ref x, ref y, ref z)); Console.WriteLine(x); Console.WriteLine(y); Console.WriteLine(z); } static void GetRandomValues(__arglist) { Random random = new Random(1); ArgIterator iterator = new ArgIterator(__arglist); while (iterator.GetRemainingCount() > 0) { TypedReference r = iterator.GetNextArg(); __refvalue(r, int) = random.Next(0, 10); } }
Michael liu
source share