When should you use struct and not class in C#? My conceptual model is that structs are used in times when the item is merely a collection of value types. A way to
Here is a basic rule.
If all member fields are value types create a struct.
If any one member field is a reference type, create a class. This is because the reference type field will need the heap allocation anyway.
Exmaples
public struct MyPoint
{
public int X; // Value Type
public int Y; // Value Type
}
public class MyPointWithName
{
public int X; // Value Type
public int Y; // Value Type
public string Name; // Reference Type
}