comm.DataReceived += comm_DataReceived; comm.DataReceived = comm_DataReceived;这两个分别是什么意思或者作用,有什么区别或者说又一个是错的.
来源:学生作业帮助网 编辑:六六作业网 时间:2024/12/20 06:33:25
comm.DataReceived += comm_DataReceived; comm.DataReceived = comm_DataReceived;这两个分别是什么意思或者作用,有什么区别或者说又一个是错的.
comm.DataReceived += comm_DataReceived; comm.DataReceived = comm_DataReceived;
这两个分别是什么意思或者作用,有什么区别或者说又一个是错的.
comm.DataReceived += comm_DataReceived; comm.DataReceived = comm_DataReceived;这两个分别是什么意思或者作用,有什么区别或者说又一个是错的.
当comm发生了DataReceived事件时通知comm_DataReceived方法并传递相关数据来处理该事件
事件是基于委托的.即delegate,实际上是.Net类库里的MultiCastDelegate类.
delegate只定义了+=和-=运算符(实际上是 +,-),所以事件(event)只定义了add和remove.
例如:
public event EventHandler Click; 实际上相当于:
public delegate void EventHandler(object sender,EventArgs e);
private EventHandler ClickHandler;
public event EventHandler Click
{
add { ClickHandler+=value;}
remove {ClickHandler-=value;}
}
所以后者(=)是错的.