namespace EventSample
{
class M
{ }
class A <T>: M
where T:M
{
public static T Instance
{
get;
private set;
}
public void cgr()
{
if (Instance == null)
{
Instance = this as T;
}
}
}
class B : A<B>
{
public int x;
}
class C : A<C>
{
public int y;
}
class Program
{
static void Main(string[] args)
{
B b = new B();
C c = new C();
b.cgr();
c.cgr();
B.Instance.x = 10;
C.Instance.y = 11;
Console.ReadKey();
}
}
}
已上代码A类有个静态属性保存子类对象,在mian入口里我先调用了 b.cgr();此时Instance里存了B类对象,由于静态的原因所有子类共用一个静态,那么在调用c.cgr()时,Instance应该不为空,静态厉害应该是B类对象啊,为什么打断点时,Instanse还为空?