委托所想

delegate是一个像class的关键字,delegate void Click_HandleEvent(object sender,string args)和class Person一样。都是定义一个类型。

当使用Click_HandleEvent handle是引用了一个类型的变量。当Person p也是引用了一个变量。

使用Fun和Action的好处是不用定义Delegate void Click_HandleEvent定义一个类型了。因为Fun和Action充当了声明一个事件。

委托作为参数的好处是,让具体的委托延迟到了调用的地方。

GetConsumeHistoryList(Action<ConsumeHistory, string> callback, string mStartTime, string mEndTime, int mStartIndex, int mCount)

{

       if (res.serverResultCode == ResultCode.STATUS_OK && null != res.readerStruct)
                    {
                        ConsumeHistory mConsumeHistory = res.readerStruct as ConsumeHistory;
                        if (null != mConsumeHistory)
                        {
                            callback(mConsumeHistory, res.serverResultCode);
                        }
                    }

}

当某个地方调用GetConsumeHistoryList时,可以具体的指定callback的函数实现过程。

原文地址:https://www.cnblogs.com/lzhp/p/3496312.html