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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T10:17:55+00:00 2026-05-12T10:17:55+00:00

I am confused by the syntax for removing event handlers in C#. Something +=

  • 0

I am confused by the syntax for removing event handlers in C#.

Something += new MyHandler(HandleSomething); // add
Something -= new MyHandler(HandleSomething); // remove

The “new” creates a new object on each line, so you add one object
and then ask it to remove a different object.

What is really going on under the covers that this can work?
It sure isn’t obvious from the syntax.

  • 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-12T10:17:55+00:00Added an answer on May 12, 2026 at 10:17 am

    The += and the -= are syntax shortcuts for built-in internal methods named Add(), and Remove(), which add or remove a pointer to an internal linked list of delegates that the delegate has as a private field. When you run Remove, it starts at the head of the linked list and examines each delegate in the list one at a time until it finds one that is “equal” to the one you passed to the Remove() method. ( using -= syntax)

    Then, it removes that one from the linked list, and patches the linked list to retain it’s connectivity…

    In this context, the ‘equals’ method (for a delegate()) is overridden so that it only compares the target of the delegate, and the methodPtr, which will be the same even though you have created a new delegate to pass to Remove…

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

Sidebar

Related Questions

I am somewhat new to ASP.NET and I am confused by the syntax so
I am currently teaching myself c# but am confused by the following syntax: new
I'm completely new to PowerShell and am confused about some of its command syntax.
I think I may be a bit confused on the syntax of the Moq
I'm a little bit confused with Html helpers in MVC3. I used this syntax
Getting confused by syntax here, but what is the difference between: foo[x][y] and foo[x,
While browsing the standard I found some syntax in the template declaration that confused
I'm quite confused in Razor syntax ))) For example I have an element: <div
I was working on some php functions and I got confused with php syntax.
As i am new to C# programming language i am a little confused about

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.