Visual C++ 2005Visual C#的对比(Visual C++2005中的组件成员)

Visual C++ 2005:

Ref class MyClass

{

     private:

         int x;

     public:

         property int X                     //组件成员:属性

{

     int get()

{

     return x;

}

 

void set(int value)

{

     x = value;

}

}

};

 

public delegate void EventHandler(Object^ sender,EventArgs^ e)  //委托

 

ref class button

{

     public:

         event EventHandler^ Click;         //组件成员:事件

}

 

public ref class Form1

{

     Button^ Button1;

void Button1_Click(Object^ sender,EventArgs^ e)

{

     ////////////////

}

 

public:

Form1()

{

Button1 = gcnew Button;

Button1->Click += gcnew EventHandler(this,&Button1_Click);    //组件成员:使用事件

}

}

 

Visual C#:

class MyClass

{

     private int x;

     public int X         // 属性

{

get

{

return x;

}

 

set

{

x = value;

}

}

};

 

public delegate void EventHandler(Object sender,EventArgs e)  //委托

 

class button

{

     public event EventHandler Click;    //事件

}

 

public class Form1

{

     Button Button1;

void Button1_Click(Object sender,EventArgs e)

{

     ////////////////

}

 

Form1()

{

Button1 = new Button();

Button1.Click += new EventHandler(Button1_Click);    //使用事件

}

}

posted on 2008-09-04 03:30  开(^_^)心  阅读(162)  评论(0编辑  收藏  举报