The following code does not call the class static constructor. Is this a bug or feature?
class Test
{
static Test
{
//do stuff
}
public static AnotherClass ClassInstance { get; set; }
}
class Program
{
public static void Main()
{
var x = Test.ClassInstance;
}
}
I don't have a compiler right now, but this is what happened to me today. The static constructor is never called, but it is called when ClassInstance is a field instead.
EDIT: I understand that static constructor is called when first instance is created or a field is accessed. Isn't there a field behind the automatic implemented property?
I am looking for some explanation on why the property does not trigger static constructor when property is implemented as two functions and one field. It is just very unlogical to me and that is why I thought it could be a bug.