// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.Reflection; namespace E { public class SomeClass { public static void SomeMethod(ref int v1, int v2) { Console.WriteLine("Inside before: " + v1 + " " + v2); v1++; Console.WriteLine("Inside after: " + v1 + " " + v2); } } public class Program { public static void Main(string[] args) { int v1 = 10; int v2 = 20; Console.WriteLine("Outside before: " + v1 + " " + v2); SomeClass.SomeMethod(ref v1, v2); Console.WriteLine("Outside after: " + v1 + " " + v2); object[] v1v2 = new object[] { v1, v2 }; typeof(SomeClass).GetMethod("SomeMethod", BindingFlags.Public | BindingFlags.Static).Invoke(null, v1v2); Console.WriteLine("Outside after: " + v1 + " " + v2 + " " + v1v2[0] + " " + v1v2[1]); typeof(SomeClass).GetMethod("SomeMethod", new Type[] { v1.GetType().MakeByRefType(), v2.GetType() }).Invoke(null, v1v2); Console.WriteLine("Outside after: " + v1 + " " + v2 + " " + v1v2[0] + " " + v1v2[1]); } } }