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 7759617
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T13:40:33+00:00 2026-06-01T13:40:33+00:00

Possible Duplicate: How to correctly unregister an event handler MSDN states the following two

  • 0

Possible Duplicate:
How to correctly unregister an event handler

MSDN states the following two event subscriptions are exactly equivalent (C# 2.0 vs 1.0 syntax):

publisher.CustomEvent += HandleCustomEvent;
publisher.CustomEvent += new CustomEventHandler(HandleCustomEvent);

I note that the newer syntax hides instantiation of a delegate object.

Do I need to keep a reference to a delegate so that I can properly unsubscribe later?

// Retain reference to delegate used to subscribe.
this.handleCustomEvent = new CustomEventHandler(HandleCustomEvent);
publisher.CustomEvent += this.handleCustomEvent;
...
// Use earlier reference to unsubscribe.
publisher.CustomEvent -= this.handleCustomEvent;

Or, is this the same thing?

publisher.CustomEvent += HandleCustomEvent;
...
publisher.CustomEvent -= HandleCustomEvent;

If they are the same, why?

Does -= HandleCustomEvent also create a new()? If so, isn’t this object different than the object created by += HandleCustomEvent?

  • 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-06-01T13:40:35+00:00Added an answer on June 1, 2026 at 1:40 pm

    This is the exact same thing I think, you just focused on the second, short-hand syntax bit.

    How to correctly unregister an event handler

    I wouldn’t answer on that just, but I wanted to add this…

    if you’d like you might want to take a look at Rx – Reactive Extensions which frees you of these very problems. Unsubscribe is basically not mandatory unless you would want to ‘stop’ the event sooner (this is simplified, there are more details to this)

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

Sidebar

Related Questions

Possible Duplicate: StructureMap singleton usage (A class implementing two interface) I'm currently designing a
Possible Duplicate: Unicode in C++ If I remembered correctly, the default character and string
Possible Duplicate: Space Before Closing Slash? Hi, If I remember correctly we have it
Possible Duplicate: Event handlers inside a Javascript loop - need a closure? I have
Possible Duplicate: Correctly encode characters in a PHP mail form (“I'm” turns to be
Possible Duplicate: Timer Won't Fire Correctly Apparently, in Java 1.6, the Timer doesn't work
Possible Duplicate: .Net Changes the element IDs I have the following problem (I'll explain
Possible Duplicate: Do I correctly understand what a class is? Before you rant and
Possible Duplicate: On iPhone: Find out what song is currently playing? (in the iPod
Possible Duplicate: Programmatically delete my own app Currently I am working on a iphone

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.