Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 244989
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T21:03:06+00:00 2026-05-11T21:03:06+00:00

Assume that I have a class that exposes the following event: public event EventHandler

  • 0

Assume that I have a class that exposes the following event:

public event EventHandler Closing

How should methods that are registered to this event be named? Do you prefer to follow the convention that Visual Studio uses when it assigns names to the methods it generates (aka. +=, Tab, Tab)? For example:

private void TheClass_Closing( object sender, EventArgs e )

Or do you use your own style to name these methods?

I’ve tried different ways to name these methods (like TheClassClosing, HandleClosing, etc.). But I haven’t found a good style to indicate that the intent of a method is to handle a registered event. I personally don’t like the style (underscore) that Visual Studio uses to generate method names.

I know that registered event-handling methods are always private and that there is no naming convention like the one for methods that raise events (e.g., OnClosing).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-11T21:03:06+00:00Added an answer on May 11, 2026 at 9:03 pm

    The two common options for naming is either after what the method does:

    theObject.Closing += SaveResults;
    

    Or alternatively after what the method handles:

    theObject.Closing += ClosingHandler;
    

    Which is preferable really depends a bit on context.

    In the first case it is immediately clear what the handler is going to do, which makes the code registering the handler more readable… but looking at the handler SaveResults in isolation it is not going to be necessarily obvious when it is going to be called, unless the event arguments have an obvious name (ClosingEventArgs or some such).

    In the second case, the registration is more opaque (okay, so what is going to happen when Closing happens?), but on the other hand, looking at the handler implementation it will be obvious what is going on.

    I guess the one to choose depends on which of the two you want to be more obvious; the site of the registration, or the implementation of the handler.

    Or alternatively, you can go for the unholy combination of both methods:

    theObject.Closing += ClosingHandlerSaveResults;
    

    Now both the registration site and the implementation are equally obvious, and neither looks particularly elegant (plus, it probably violates the DRY principle).

    For the record I prefer the first naming scheme when theObject is contained in a different scope from the implementation of SaveResults, and the second scheme when I am wiring up handlers to events that are all contained within the same class.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Assume I have a class that looks like this: class Sample { public string
Assume that I have the following object public class MyClass { public ReadOnlyDictionary<T, V>
Assume that we have the following code: class Program { static volatile bool flag1;
So let's assume I have a class named ABC that will have a list
Assume some domain and view objects (that have no common base class) public class
Let's assume that I have following models: class ScoutBook(models.Model): troop = models.ForeignKey('Dictionary', limit_choices_to={'type' :
Assume that we have two classes public class EntityA { public EntityB EntityB {
Assume that I have a .NET Workflow Foundation (WF) SequenceActivity class with the following
Assume that we have class public class RMenuItem { public List<RMenuItem> ChildrenItems { get;
assume that I have the following obejct: class title { string Title; int id;

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.