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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:52:04+00:00 2026-06-06T13:52:04+00:00

In .NET, if I’m implementing an interface that contains an event, but that event

  • 0

In .NET, if I’m implementing an interface that contains an event, but that event makes no sense for my object (say it’s a change event and I’m writing an immutable object), then I can just provide empty bodies for add and remove — a null implementation. This avoids allocating storage for a delegate field I’ll never use, and also avoids the “event is never used” compiler warning, so it’s a win all around.

public event EventHandler Changed {
    add {}
    remove {}
}

When I try the same thing in a WinRT class (descends from FrameworkElement), I get a compiler error on the add accessor: “not all code paths return a value”.

How do I return a value from an add accessor? What’s it supposed to return?

Update: Apparently this problem only applies to WinRT events (e.g., if you’re implementing a WinRT interface that contains an event). If you’re writing a plain old CLR event, the above syntax works.

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

    So based on the link Anders posted, it looks like the add accessor needs to return an EventRegistrationToken. EventRegistrationToken is just a struct, apparently with no fields, and no constructors beyond the default, so it looks like I could harmlessly new one up — especially since the only code that will consume it is my remove, which doesn’t care.

    So the WinRT equivalent of the null event appears to be:

    public event EventHandler Changed {
        add { return new EventRegistrationToken(); }
        remove {}
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

.NET provides EventLog class that be able to write application event information to a
.Net framework contains a great class named Convert that allows conversion between simple types,
net project then it runs in mozilla. I want to change that setting &
.Net contains a nice control called DocumentViewer . it also offers a subcontrol for
.NET framework 3.5 introduces Action and Func<> predefined delegate types that are very handy.
.NET contains its own equality comparison functionality, however I don't really understand how it
.NET 4, EF 4 I have two related entities, Order and OrderLine. Order contains
net ajax app. I have one modelpopup that shows a IFrame and inside Iframe
.NET 3.5 was different and co-existed along with .NET 2.0. Is that still the
.NET Programming guidelines state that we should not catch general exceptions. I assume the

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.