开发者

Am I missing something or is this not right way to declare event?

I came across this p开发者_C百科iece of code. It works, but is it not against the .net event declaration guidelines?

public event Action SessionTimeout;


While it is against standard C# practice, it is not an invalid event decleration.


The convention is that a .NET event uses a delegate that takes two parameters: the sender and the event arguments. However, this is an API convention, not a requirement. You may declare an event of any delegate type.


I would change it to:

public event Action SessionTimeout = delegate {};

So you don't have to check for null before raising it. I assume the potential extra CPU cycle this will cause won't affect your performance :)

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜