C# 编程/关键字/add
外观
< C Sharp 编程 | 关键字
关键字add 和 remove 允许您在委托添加到或从事件中移除时执行代码。它的用法类似于属性的get 和 set 关键字
public event MyDelegateType MyEvent
{
add
{
// here you can use the keyword "value" to access the delegate that is being added
...
}
remove
{
// here you can use the keyword "value" to access the delegate that is being removed
...
}
}
当委托添加到事件时,add 块中的代码将被执行。类似地,当委托从事件中移除时,remove 块中的代码将被执行。
| C# 关键字 | |||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| C# 特殊标识符(上下文关键字) | |||||||||||||||
| |||||||||||||||
| 上下文关键字(用于查询) | |||||||||||||||
|