CSharp - Data Types Value types

Introduction

The content of a value type variable is a value.

For example, the content of the built-in value type, int, is 32 bits of data.

You can define a custom value type with the struct keyword:

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

The assignment of a value-type instance always copies the instance. For example:

Demo

using System;

struct Point { public int X, Y; }
class MainClass/*from   w ww  .  j  av a2s .co  m*/
{
   public static void Main(string[] args)
   {
       Point p1 = new Point();
       p1.X = 1;

       Point p2 = p1;             // Assignment causes copy

       Console.WriteLine (p1.X); 
       Console.WriteLine (p2.X); 

       p1.X = 2;                  // Change p1.X

       Console.WriteLine (p1.X); 
       Console.WriteLine (p2.X);  
   }
}

Result