static void convert(MyClass my1, myStruct my2) { my1.x = 5; my1.y = 5; Console.WriteLine("In (class) : my1.x = {0}, my1.y = {1}", my1.x, my1.y); my2.x = 8; my2.y = 8; Console.WriteLine("In (struct) : my2.x = {0}, my2.y = {1}", my2.x, my2.y); }
static void Main(string[] args) { MyClass my1 = new MyClass(); my1.x = 10; my1.y = 20; Console.WriteLine("Before (class) : my1.x = {0}, my1.y = {1}", my1.x, my1.y); myStruct my2 = new myStruct(); my2.x = 30; my2.y = 40; Console.WriteLine("Before (struct) : my2.x = {0}, my2.y = {1}", my2.x, my2.y); convert(my1, my2); Console.WriteLine("After (class) : my1.x = {0}, my1.y = {1}", my1.x, my1.y); Console.WriteLine("After (struct) : my2.x = {0}, my2.y = {1}", my2.x, my2.y); }