class vs struct : struct « struct « C# / CSharp Tutorial






using System;
using System.Collections.Generic;
using System.Text;



class MyClass {
    public int val;
}

struct myStruct {
    public int val;
}

class Program {
    static void Main(string[] args) {
        MyClass objectA = new MyClass();
        MyClass objectB = objectA;
        objectA.val = 10;
        objectB.val = 20;
        myStruct structA = new myStruct();
        myStruct structB = structA;
        structA.val = 30;
        structB.val = 40;
        Console.WriteLine("objectA.val = {0}", objectA.val);
        Console.WriteLine("objectB.val = {0}", objectB.val);
        Console.WriteLine("structA.val = {0}", structA.val);
        Console.WriteLine("structB.val = {0}", structB.val);
    }
}








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