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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T21:04:38+00:00 2026-06-01T21:04:38+00:00

In the program I am creating, I have a large amount of enums enum

  • 0

In the program I am creating, I have a large amount of enums

enum kEvents
{
    Start = 0,
    End,
    EntityCreated,
}

In this program, there is a huge list of Entities.
Each entity holds a list of “kEvents” that it is “Registered to”

Every time an object says “Call the Start event” I have to iterate through every single entity in the game, and find out if they are “listening” for that event.

Note: I know that c# has event handlers, but I was hoping to create this enum system from the ground up instead.

This being the case, what is the best way to:

  1. Hold the collection of enums in each entity object
  2. Check if the entity holds the triggered enum

I am wondering if Enums, being basically numbers, have a lower level, quicker way to handle this than a List<T> of objects.

  • 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-01T21:04:39+00:00Added an answer on June 1, 2026 at 9:04 pm

    Every time an object says "Call the Start event" I have to iterate through every single entity in the game, and find out if they are "listening" for that event.

    You’re doing it wrong! Iterating over every single object and checking if they’re registered for an event is very inefficient! This is the typical Observer design pattern and there are several ways to go about this, here are a couple:

    1. Have a single event which gets raised and has an enum parameter for event type (every subscriber gets it).
    2. Have a dictionary of enums and corresponding events.

    Here is what option 1 might look like:

    delegate void OnEventDelegate(kEvents anEvent);
    public class MyEventObservable
    {
        public event OnEventDelegate OnEvent;
    }
    
    public class MyEventObserver
    {
        // Constructors and all
        // ...
    
        public void OnEventReceived(kEvents anEvent)
        {
            switch(anEvent)
            {
                // switch through all the events and handle the ones that you need
            }
        }
    }
    
    MyEventObserver observer = new MyEventObserver();
    MyEventObservable observable = new MyEventObservable();
    observable.OnEvent += new OnEventDelegate(observer.OnEventReceived);
    

    Here is option 2:

    public class MyEventObservable
    {
        private Dictionary<kEvents, List<IObserver>> _observers;
        
        MyEventObservable()
        {
            // Initialize the dictionary with all the events
        }
        
        public void RegisterObserver(kEvents event, IObserver observer)
        {
            _observers[event].Add(observer);
        }
    }
    
    interface class IObserver
    {    
        void Notify(kEvents anEvent);
    }
    
    public MyEventObserver: IObserver
    {
        // Constructors and all
        // ...
        
        // Override the IObserver
        public void Notify(kEvents anEvent)
        {
            switch(anEvent)
            {
                // switch through all the events and handle the ones that you need
            }
        }
    }
    
    MyEventObserver observer = new MyEventObserver();
    MyEventObservable observable = new MyEventObservable();
    observable.RegisterObserver(kEvents.Start, observer);
    

    Option two will reduce the number of events each observer has to handle, but it comes at the cost of having to register for every event separately (which adds coding complexity). This means that option 2 will work faster because there are fewer function calls to make. Depending on how "crazy" you want to get with the performance, there might be other options that can help you to speed it up but this should set you on the right track.

    P.S. I have not compiled any of the code, but it should give you a general idea of how things ought to work.

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

Sidebar

Related Questions

I have a Java program that reads in a large list of strings from
I have been tasked with creating a program that will generate an amortization schedule.
I have been tasked with creating a program what will create take files in
The program I've written stores a large amount of data in dictionaries. Specifically, I'm
We have a fairly simple program that's used for creating backups. I'm attempting to
I am having fun creating my own wallpaper changer program. I know there are
I have a large old program which has some rather complex graphical displays (all
Im building a relatively large object-oriented program. I have a class called AerodynamicCalculator that
I have little program creating a maze. It uses lots of collections (the default
Here's what I'm trying to do. I have an extremely large list of items.

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.