类中定义自身类对象

来源:互联网 发布:单片机交通灯设计方案 编辑:程序博客网 时间:2024/06/05 01:53

1:由于类属于引用类型,所有在为实例化之前,其相当一个空指针(不能在构造函数中对其实例化,否则会陷入死循环)

但可以将其指向自身。

class Program    {        Program tT;        Program( )        {            tT = this;        }static void Main( string[] args )        {            Program a = new Program();//实例化的时候不会陷入死循环。            int temp;            temp = 0;        }}



0 0
原创粉丝点击