用C#创建的Form,画一个按钮,看代码时实在搞不懂下面到底是什么意思.类form1中如下声名: private System.Windows.Forms.Button button1;  //这里button1是个对像吗?而private void InitializeComponent()中又是如下处理的:this.button1 = new System.Windows.Forms.Button();//这里button1是个指针吗?为什么会这样?假设private System.Windows.Forms.Button button1;是一个对像,那么在初始化时,应该是this.button1.Create()来创建,既然C#中不区分指针与对像,却又使用new来创建,真是费解。

解决方案 »

  1.   

    this是当前对象实例,this.button1 是当前对象实例的成员,也是一个对象实例
      

  2.   

    在面向对象语言中,一切东西都是对象.
    所以,你第一个问题答案是:对象.
    第二:给button1这个对象分配内存空间.
      

  3.   

    第二个是分配内存空间,System.Windows.Forms.Button()不就是Button类的构造函数吗?类的成员private System.Windows.Forms.Button button1难道在构造时,没有执行构造函数Button?还需要单独来分配空间?
      

  4.   

    private System.Windows.Forms.Button button1;//声明
    this.button1 = new System.Windows.Forms.Button();//初始化,分配内存空间

    private System.Windows.Forms.Button button1 = new System.Windows.Forms.Button();
    是一样的。
      

  5.   

    如果说private System.Windows.Forms.Button button1 = new System.Windows.Forms.Button();这样的话,那么button1就是一个指针了?是否也等同于下面:
    Button button1= new Button();那么,System.Windows.Forms.Button()是什么?不是Button类的静态构造函数吗?如果button1是一个对像,那么可以用自己的成员函数来处理,比如this.button1.Button(),为什么还要用new来分配?new产生了一个对像,赋给了button1,而button1又是一个对像,原指向的对像不就找不到了?内存泄露?
      

  6.   

    private System.Windows.Forms.Button button1;  
    定義變量。
    this.button1 = new System.Windows.Forms.Button();
    為變量分配內存空間。
      

  7.   

    Button()是什么?
    如果说private System.Windows.Forms.Button button1;仅仅是声名变量,那么下面:
    string string1;
    这句又如何解释?从来没见哪里这样写:string1=new string();
      

  8.   


    第二个是分配内存空间,System.Windows.Forms.Button()不就是Button类的构造函数吗?类的成员private System.Windows.Forms.Button button1难道在构造时,没有执行构造函数Button?还需要单独来分配空间?  
    ////
    对了,只有new时才分配内存。前面只是告诉编译器。他是个什么类型的对象
      

  9.   

    有点类似的和C++,在C++里,我记得也是要给对象New的时候才会触发其构造函数的!