Event naming conventions

  • Thread starter Thread starter Mantorok
  • Start date Start date
M

Mantorok

Hi all

This has baffled me for a bit now, what is a recommended naming convention
for events, my thought was the events should just be named as in the .Net
framework, ie Click.

However, some people feel preceding the name with "On" is necessary, is that
right?

Any thoughts on this?
Thanks
Kev
 
Hi,

The guideliness are to name it without On. The On prefix is added to
protected virtual method that launches the event, for example:
public event EventHandler SomeEvent;

protected virtual void OnSomeEvent(EventArgs e)
{
if (SomeEvent != null)
SomeEvent(this, e);
}
 
Thanks, that's confirmed my thoughts too.

Kev

Miha Markic said:
Hi,

The guideliness are to name it without On. The On prefix is added to
protected virtual method that launches the event, for example:
public event EventHandler SomeEvent;

protected virtual void OnSomeEvent(EventArgs e)
{
if (SomeEvent != null)
SomeEvent(this, e);
}

--
Miha Markic [MVP C#]
RightHand .NET consulting & development www.rthand.com
Blog: http://cs.rthand.com/blogs/blog_with_righthand/

Mantorok said:
Hi all

This has baffled me for a bit now, what is a recommended naming
convention for events, my thought was the events should just be named as
in the .Net framework, ie Click.

However, some people feel preceding the name with "On" is necessary, is
that right?

Any thoughts on this?
Thanks
Kev
 
Back
Top