Pet*_*r T 8 c# resharper singleton
在深度C#中建议的单例模式实现是
public sealed class Singleton
{
private static readonly Singleton instance = new Singleton();
static Singleton()
{
}
private Singleton()
{
}
public static Singleton Instance
{
get
{
return instance;
}
}
}
Run Code Online (Sandbox Code Playgroud)
ReSharper建议使用auto属性和C#6自动属性初始化器简化它:
public sealed class Singleton
{
static Singleton()
{
}
private Singleton()
{
}
public static Singleton Instance { get; } = new Singleton();
}
Run Code Online (Sandbox Code Playgroud)
这确实看起来更简单.使用这种简化有不足之处吗?
| 归档时间: |
|
| 查看次数: |
449 次 |
| 最近记录: |