Copy a struct. : struct copy « struct « C# / CSharp Tutorial






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








6.8.struct copy
6.8.1.Copy a struct.
6.8.2.Copy a struct instance by assignment