public sealed class Singleton
{
Singleton() {}
public static Singleton Instance
{
get
{
return Nested.instance;
}
}
class Nested
{
// Explicit static constructor to tell C# compiler
// not to mark type as beforefieldinit
static Nested() {}
internal static readonly Singleton instance = new Singleton();
}
}
我希望在当前的C#应用程序中实现Jon Skeet的Singleton模式。
我对代码有两个疑问
如何访问嵌套类内部的外部类?我的意思是
internal static readonly Singleton instance = new Singleton();
是所谓的关闭吗?
我无法理解此评论
// Explicit static constructor to tell C# compiler // not to mark type as beforefieldinit
此评论对我们有什么建议?