开发者

Store a reference to a method

开发者 https://www.devze.com 2023-03-01 11:40 出处:网络
I\'m trying to create a wrapper around a logging method (Debug.Log) in Unity3d. What I want to do is declare a variable inside whatever class I ha开发者_如何学运维ppen to be working on to shorthand My

I'm trying to create a wrapper around a logging method (Debug.Log) in Unity3d. What I want to do is declare a variable inside whatever class I ha开发者_如何学运维ppen to be working on to shorthand MyDebug.Log('something') into just L('something'). My problem is I can't figure out how to actually store a reference to the method like that.


Try this:

Action<string> L = MyDebug.Log;

http://msdn.microsoft.com/en-us/library/018hxwa8.aspx


You can use a Action<T> delegate for this. Just use a generic one with how many type parameters you need.

0

精彩评论

暂无评论...
验证码 换一张
取 消