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

  • Home
  • SEARCH
  • 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 9158799
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:20:08+00:00 2026-06-17T13:20:08+00:00

Suppose I have some event in a class: class SomeClass{ event ChangedEventHandler SomeDoubleChanged; double

  • 0

Suppose I have some event in a class:

 class SomeClass{
     event ChangedEventHandler SomeDoubleChanged;
     double SomeDouble;
 }

with:

 delegate void ChangedEventHandler(double d);

Now suppose I want to listen for change events on SomeDouble, but only want to trigger changes greater than delta. Now I could do something like

 SomeObject.SomeDoubleChanged += (d) => {if(abs(d-old_d) > delta){
                                  //do something     
                                 };

But I want my event to handle this, so in the best case I want to do something like:

 SomeObject.SomeDoubleChange += (delta, (d) => {});

and still allow:

 SomeObject.SomeDoubleChange += (d) => {};

The only way I only way I thought of implementing this, is to drop the whole event keyword and implement a container with += and -= operators, operating on the specified delegates. But in my opinion this is not a very elegant solution, as it gives the user of SomeClass the idea that SomeDoubleChanged is no event.

What would be the most elegant solution to this problem?

  • 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-17T13:20:09+00:00Added an answer on June 17, 2026 at 1:20 pm

    (I’d recommend not using the term “lambda” here given that you’re also using lambda expressions. It sounds like you’re interested in the change, i.e. the delta.)

    You could create your own static methods to create appropriate delegates:

    public static ChangedEventHandler FilterByDelta(double delta,
                                                    ChangedEventHandler handler)
    {
        double previous = double.MinValue;
        return d =>
        {            
            if (d - previous > delta)
            {
                handler(d);
            }
            // Possibly put this in the "if" block? Depends on what you want.
            previous = d;
        };
    }
    

    Then you can use:

    SomeObject.SomeDoubleChange += Helper.FilterByDelta(5, d => ...);
    

    Unfortunately you can’t use extension methods on lambda expressions, which would make this easier.

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

Sidebar

Related Questions

Suppose I have some application A with a database. Now I want to add
I have a custom event handler, or I suppose some call it a custom
Suppose I have some class which has a property actor_ of type Actor .
Suppose I have some pointer, which I want to reinterpret as static dimension array
suppose I have this string: some striinnngggg <a href=something/some_number>linkk</a> soooo <a href=someotherthing/not_number>asdfsadf</a> I want
Suppose you have some method that could be made static, inside a non-static class.
Suppose I have an event KeyPress subscribed to by various classes. Assume that Class
Suppose you have some complex JSON like: {A : valA, B : { C
Propose to consider the following problem. Suppose we have some composite object. Are there
Lets suppose that I have some pages some.web/articles/details/5 some.web/users/info/bob some.web/foo/bar/7 that can call a

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.