Visual C++ 2005 系列课程学习笔记-5

本文对比了Visual C++ 2005与Visual C#中组件成员的实现方式,包括属性、委托和事件的定义及使用方法。通过具体的代码示例展示了两种语言在这些特性上的异同。

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);    //使用事件

}

}

转载于:https://www.cnblogs.com/kai_xin/archive/2008/09/04/1283519.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值