I just tested this code in Console apps targeting .NET Framework 4.8 and .NET 5.0:
class Program
{
static void Main()
{
var t1 = new Thing();
var t2 = new Thing();
Console.WriteLine(t1.Name);
Console.WriteLine(t2.Name);
Console.ReadLine();
}
}
class Thing
{
private static int Count = 0;
public readonly string Name;
public Thing()
{
Count++;
Name = Count.ToString();
}
}
In both cases, it worked exactly the same way and exactly as you'd expect. I suspect that there's something else going on in your project and you just haven't debugged properly. As suggested, an
int
can't be
null
so, at the very least, your description is inaccurate.