c#中的?.Invoke,即问号点Invoke

转自:https://hovertree.com/h/bjag/4dmf8x0u.htm

 

public delegate void OperateSuccessHanlder(string fileName); //创建委托
public event OperateSuccessHanlder OperateSuccess;
//UCPictureAdd.ascx.cs中的代码
void OnOperateSuccess(string fileName)
        {
            OperateSuccess?.Invoke(fileName);
        }

  

上面代码等价于:

public delegate void OperateSuccessHanlder(string fileName); //创建委托
public event OperateSuccessHanlder OperateSuccess;
//UCPictureAdd.ascx.cs中的代码
void OnOperateSuccess(string fileName)
        {
           if(OperateSuccess!=null)
            {
                OperateSuccess(fileName);
            }
        }

  

posted @ 2021-06-02 19:56  包子789654  阅读(1421)  评论(1编辑  收藏  举报