Reference value type in a struct : struct « struct « C# / CSharp Tutorial






using System;

struct Point
{
   public int X;
   public int Y;
}

class MainClass
{
   static void Main()
   {
      Point p1, p2, p3;

      p1.X = 10; p1.Y = 10;
      p2.X = 20; p2.Y = 20;
      p3.X = p1.X + p2.X;
      p3.Y = p1.Y + p2.Y;

      Console.WriteLine("p1:  {0}, {1}", p1.X, p1.Y);
      Console.WriteLine("p2: {0}, {1}", p2.X, p2.Y);
      Console.WriteLine("p3:  {0}, {1}", p3.X, p3.Y);
   }
}
p1:  10, 10
p2: 20, 20
p3:  30, 30








6.1.struct
6.1.1.Structures
6.1.2.Declare a simple struct
6.1.3.A simple struct with method
6.1.4.class vs struct
6.1.5.Reference value type in a struct
6.1.6.struct with value types
6.1.7.struct with value types and ref types
6.1.8.Difference between class and struct during the reference passing