各位大虾,请问下,委托能否引用操作符函数
如
TimeHour timeVar =new TimeHour();
Timer t=new Timer(100);
t.Elapsed +=new ElapsedEventHandler(+(timeVar));其中,TimeHour自定义的类,重载了+运算符
如
TimeHour timeVar =new TimeHour();
Timer t=new Timer(100);
t.Elapsed +=new ElapsedEventHandler(+(timeVar));其中,TimeHour自定义的类,重载了+运算符
是一个事件,他原先的委托和你现在用的委托如果声明相同就可以用,但实际情况却不是这用,看你的程序 委托声明应该是:
delegate void TimeHour();和 Elapsed 的委托声明不符。其实大部分时候没必要用委托,直接调用函数就可以了,
Timer t=new Timer(100);
t.Elapsed +=new ElapsedEventHandler(+(timeVar));其中,TimeHour自定义的类,重载了+运算符
/***********************************************你这些代码是错的。
首先,delegate:ElapsedEventHandler这个委托它只能封装返回值为空,带两个参数的函数:
即:void **** (object obj , System.Timers.ElapsedEventArgs e),函数名不重要
你的函数显然不符合这个委托的定义,所以不能t.Elapsed +=new ElapsedEventHandler(+(timeVar));
还有,你必须弄明白,使用委托的意义所在,我想对于你的这个需求应该没有必要使用委托吧。
个人意见,嘿嘿……