C#에서의 Singleton 구현을 위해 [http]Implementing the Singleton Pattern in C#을 읽다가 이상한 것을 발견했다.

public sealed class Singleton { static readonly Singleton instance=new Singleton(); // Explicit static constructor to tell C# compiler // not to mark type as beforefieldinit static Singleton() { } Singleton() { } public static Singleton Instance { get { return instance; } } }

Explicit static constructor to tell C# compiler not to mark type as beforefieldinit
이게 무슨 소리?

[http]여기에서 인용한 ECMA335 를 보면,
  1. If marked BeforeFieldInit then the type's initializer method is executed at, or sometime before, first access to any static field defined for that type
  2. If not marked BeforeFieldInit then that type's initializer method is executed at (i.e., is triggered by):
    • first access to any static or instance field of that type, or
    • first invocation of any static, instance or virtual method of that type

powered by Moniwiki | themed by clockoon
last modified 2008-12-30 10:44:14
Processing time 0.1426 sec