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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T03:42:34+00:00 2026-06-15T03:42:34+00:00

I have an abstract class A which has a required function for checking thresholds.

  • 0

I have an abstract class A which has a required function for checking thresholds. When a threshold is violated I want an event raised that says notify me. I’ve done this sort of thing in Qt many times, but I can’t seem to figure out how to transfer this to C#. Here’s the structure I’ve currently got in mind.

namespace N
{
  abstract class A
  {
    public delegate void Notify();
    public event Notify Notifier;
    public abstract void CheckThreshold();
  }

  class B : A
  {
    public override void CheckThreshold()
    {
       Notifier();
    }
  }

  class N
  {
    public AlertMe()
    {
    }
    public static Main()
    {
      var b = new B();
      b.Notifier += new A.Notify(AlertMe);

      b.CheckThreshold();
    }
  }
}
  • 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-15T03:42:35+00:00Added an answer on June 15, 2026 at 3:42 am

    Typically the form you want to follow is this:

    public event EventHandler<SomeEventArgs> SomeEvent = (s, e) => { };
    
    protected virtual void OnSomeEvent(SomeEventArgs e)
    {
        SomeEvent(this, e);
    }
    

    so in your case you probably want:

    abstract class A {
    
        public event EventHandler<EventArgs> ThresholdExceeded = (s, e) => { };
    
        protected virtual void OnThresholdExceeded(EventArgs e)
        {
            ThresholdExceeded(e);
        }
    
        public abstract void CheckThreshold();
    }
    
    class B : A {
        public override void CheckThreshold()
        {
            if (/* your condition */) OnThresholdExceeded(new EventArgs());
        }
    }
    

    Now a few things – the EventHandler type is some nice syntactic sugar for making an event of a particular type. The lambda expression on the right initializes it to a default handler so you don’t have to check it for null before you invoke it.

    EventArgs is event-specific information – you have none, but if you did you would subclass EventArgs and put in whatever data your event receivers would need.

    The pattern of public event SomeEventName and protected virtual void OnSomeEvent pair is prescribed by Microsoft for events in .NET. You don’t have to follow this, but it’s what .NET programmers want.

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

Sidebar

Related Questions

I have an Abstract class called Function which has 2 inheriting classes (actually 6,
I have an abstract class Exception in custom namespace which has no abstract methods.
I have created an abstract base class, which has a pure virtual method with
I have an abstract class which has a Protected Method. I am using dictionary
I have a abstract class called Customer which has some attributes shared amongst all
I have 1 abstract class that is calling a static method which up until
I have a abstract class which has some common methods for all of my
So basically, I have an abstract class which has a unique, incremental ID -
I have an abstract class which contains method for setting header text. It looks
In my console application have an abstract Factory class Listener which contains code for

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.