代码语言:javascript复制
public class ProteType
{
private static ProteType _ProteType = new ProteType();
private ProteType() { }
public static ProteType GetInstance()
{
return (ProteType)_ProteType.MemberwiseClone();
}
}
运行测试
代码语言:javascript复制 var a1 = ProteType.GetInstance();
var a2 = ProteType.GetInstance();
Console.WriteLine($"a1 和 a2 是同一实例:{ object.ReferenceEquals(a1, a2)}");
源码下载:https://gitee.com/weilong2020/csharp_23_-design-patterns.git