Reputation: 17637
I came across this piece of code. It works, but is it not against the .net event declaration guidelines?
public event Action SessionTimeout;
Upvotes: 2
Views: 79
Reputation: 20992
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.
Upvotes: 1
Reputation: 83358
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 :)
Upvotes: 1
Reputation: 61437
While it is against standard C# practice, it is not an invalid event decleration.
Upvotes: 3