如果你真的想要这样的行为,我认为最好的选择是使用重载add {}和remove {}功能.
public class Foo
{
private EventHandler<ElapsedEventArgs> _elapsed;
public EventHandler<ElapsedEventArgs> Elapsed
{
add
{
if( _elapsed == null )
_elapsed += value;
else
throw new InvalidOperationException ("There is already an eventhandler attached to the Elapsed event.");
}
remove
{
_elapsed -= value;
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1974 次 |
| 最近记录: |