What is the difference between C# Class and Struct?


Struct is Value Type
Struct is stored in Stack

Class is Reference Type
Class is stored in heap memory allocation

Like classes, structs are data structures that can contain data members and function members, but unlike classes, structs are value types and do not require heap allocation. 
A variable of a struct type directly stores the data of the struct, whereas a variable of a class type stores a reference to a dynamically allocated object.

Structs are particularly useful for small data structures that have value semantics. Complex numbers, points in a coordinate system, or key-value pairs in a dictionary are all good examples of structs.

For example, the following program creates and initializes an array of 100 points. With Point implemented as a class, 101 separate objects are instantiated—one for the array and one each for the 100 elements.

public class PointExample
{
    public static void Main() 
    {
        Point[] points = new Point[100];
        for (int i = 0; i < 100; i++)
            points[i] = new Point(i, i);
    }

}

An alternative is to make Point a struct

struct Point
{
    public int x, y;
    public Point(int x, int y) 
    {
        this.x = x;
        this.y = y;
    }
}

Struct constructors are invoked with the new operator, similar to a class constructor
 Point a = new Point(10, 10);
Point b = a;
a.x = 20;
Console.WriteLine(b.x);

If Point is a class, the output is 20 because a and b reference the same object. If Point is a struct, the output is
10 because the assignment of a to b creates a copy of the value, and this copy is unaffected by the subsequent
assignment to a.x