Event naming conventions

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
 
M

Miha Markic [MVP C#]

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);
}
 
M

Mantorok

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top