void Test()
{
Test.Instance.a++;
Console.WriteLine("Test:" + Test.Instance.a);
}
struct Test
{
public static Test Instance = new();
public int a;
}
Will the Test.Instance object be stored on heap or on stack and why?
They can't be stored on the stack as their is no stack frame associated with static data.
And according to Jon Skeet's blog, "Every static variable is stored on the heap."