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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T09:07:33+00:00 2026-05-12T09:07:33+00:00

I recently started digging into C# but I can’t by my life figure out

  • 0

I recently started digging into C# but I can’t by my life figure out how delegates work when implementing the observer/observable pattern in the language.

Could someone give me a super-simple example of how it is done? I have googled this, but all of the examples I found were either too problem-specific or too “bloated”.

  • 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-12T09:07:34+00:00Added an answer on May 12, 2026 at 9:07 am

    The observer pattern is usually implemented with events.

    Here’s an example:

    using System;
    
    class Observable
    {
        public event EventHandler SomethingHappened;
    
        public void DoSomething() =>
            SomethingHappened?.Invoke(this, EventArgs.Empty);
    }
    
    class Observer
    {
        public void HandleEvent(object sender, EventArgs args)
        {
            Console.WriteLine("Something happened to " + sender);
        }
    }
    
    class Test
    {
        static void Main()
        {
            Observable observable = new Observable();
            Observer observer = new Observer();
            observable.SomethingHappened += observer.HandleEvent;
    
            observable.DoSomething();
        }
    }
    

    See the linked article for a lot more detail.

    Note that the above example uses C# 6 null-conditional operator to implement DoSomething safely to handle cases where SomethingHappened has not been subscribed to, and is therefore null. If you’re using an older version of C#, you’d need code like this:

    public void DoSomething()
    {
        var handler = SomethingHappened;
        if (handler != null)
        {
            handler(this, EventArgs.Empty);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Recently I started digging into the concept of Repository Patterns and UnitOfWork together with
I recently started digging into design patterns. Generally speaking, I thought the design issues
I recently started learning 0MQ . Earlier today, I ran into a blog, Python
I´ve recently started looking a web service calls using PHP. I can´t get the
I recently started working with CakePHP but there are a few things I don't
I recently started using rvalue references and I've run into a case where I
I recently started work on a personal coding project using C++ and KDevelop. Although
I recently started using Eclipse at work for my Java servlet projects. I've been
I recently started falling in love with the play! framework but now I am
I recently started looking into django and I started with the tutorial. I noticed

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.