Mega Code Archive

 
Categories / C# Tutorial / Struct
 

Copy a struct

using System;    struct MyStruct {    public int x;  }    class MainClass {    public static void Main() {      MyStruct a;      MyStruct b;        a.x = 10;      b.x = 20;        Console.WriteLine("a.x {0}, b.x {1}", a.x, b.x);        a = b;      b.x = 30;        Console.WriteLine("a.x {0}, b.x {1}", a.x, b.x);    }  } a.x 10, b.x 20 a.x 20, b.x 30