The following code does not call the static constructor of the class. Is this a bug or function?
class Test
{
static Test
{
}
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. A static constructor is never called, but it is called when ClassInstance is a field.
EDIT: I understand that the static constructor is called when the first instance is created or when the field is accessed. Isn't there a field behind an automatically implemented property?
I am looking for some explanation why a property does not call a static constructor when a property is implemented as two functions and one field. It is just very illogical for me, and that is why I thought it might be a mistake.
source
share