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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:17:42+00:00 2026-06-13T09:17:42+00:00

Let’s say I have an enum called eEventID that contains 10 events, mEvent1 –

  • 0

Let’s say I have an enum called eEventID that contains 10 events, mEvent1 - mEvent10 with int values 10001 – 10010 . I want to use an input value (e.g. 10007) to check if a member in the enum has the corresponding value. Once I find the event with the corresponding input value, I then take that event and register a method to it by hooking up a delegate (This is assuming I have all the necessary code). I just need to know if a member in the enum has a value that is the same as the input value, then register a new method to that event. How do I look for a certain event using only an input value? I’m guessing a for-loop or any other loop isn’t my best bet.

EDIT: this is what I have so far…

public delegate void EventDel(int mEvtIdx);

public enum eVtEvtId
{
    Event1,
    Event2,
    Event3,
    Event4,
    Event5,
    Event6,
    Event7,
    Event8,
    Event9,
    Event10,

}

public void Subscribe(int mInVal)
{
    eVtEvtID mEventID;
    int mEventIndex = mInVal;

    if(Enum.IsDefined(typeof(mEventID), mEventIndex))
    {
        mEventID += EventDelegate([insert method here])
    }

    else
    {
        // will warn the user that the event does
        // not yet exist in the enum
    }

}
  • 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-13T09:17:43+00:00Added an answer on June 13, 2026 at 9:17 am

    Here’s an example that demonstrates how you would take a value (reading it from the console) map it to the numeric value corresponding to an enum member, locate the corresponding event (in this case on the Program class) and attach an event handler to it.

    using System;
    
    namespace ConsoleApplication6
    {
        public enum Events
        {
            Event1 = 10001,
            Event2 = 10002,
            Event3 = 10003,
            Event4 = 10004,
            Event5 = 10005,
            Event6 = 10006,
            Event7 = 10007,
            Event8 = 10008,
            Event9 = 10009,
            Event10 = 10010
        }
    
        public class Program
        {
            public static event Action Event1;
            public static event Action Event2;
            public static event Action Event3;
            public static event Action Event4;
            public static event Action Event5;
            public static event Action Event6;
            public static event Action Event7;
            public static event Action Event8;
            public static event Action Event9;
            public static event Action Event10;
    
            private static void OnEvent1()
            {
                if(Event1 != null)
                {
                    Event1();
                }
            }
    
            private static void OnEvent2()
            {
                if (Event2 != null)
                {
                    Event2();
                }
            }
    
            private static void OnEvent3()
            {
                if (Event3 != null)
                {
                    Event3();
                }
            }
    
            private static void OnEvent4()
            {
                if (Event4 != null)
                {
                    Event4();
                }
            }
    
            private static void OnEvent5()
            {
                if (Event5 != null)
                {
                    Event5();
                }
            }
    
            private static void OnEvent6()
            {
                if (Event6 != null)
                {
                    Event6();
                }
            }
    
            private static void OnEvent7()
            {
                if (Event7 != null)
                {
                    Event7();
                }
            }
    
            private static void OnEvent8()
            {
                if (Event8 != null)
                {
                    Event8();
                }
            }
    
            private static void OnEvent9()
            {
                if (Event9 != null)
                {
                    Event9();
                }
            }
    
            private static void OnEvent10()
            {
                if (Event10 != null)
                {
                    Event10();
                }
            }
    
            static void Main(string[] args)
            {
                while(true)
                {
                    var input = Console.ReadLine();
    
                    if(input == "q")
                    {
                        return;
                    }
    
                    int value;
    
                    if(int.TryParse(input, out value))
                    {
                        var eventValue = (Events) value;
                        var eventName = Enum.GetName(typeof (Events), eventValue);
    
                        var matchingEvent = typeof(Program).GetEvent(eventName);
    
                        if (matchingEvent != null)
                        {
                            var action = new Action(() => Console.WriteLine("Event " + eventName + " has been handled"));
                            matchingEvent.AddEventHandler(null, action);
                        }
    
                    }
    
                    OnEvent1();
                    OnEvent2();
                    OnEvent3();
                    OnEvent4();
                    OnEvent5();
                    OnEvent6();
                    OnEvent7();
                    OnEvent8();
                    OnEvent9();
                    OnEvent10();
                }
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say you have a class called Customer, which contains the following fields: UserName
Let me explain best with an example. Say you have node class that can
Let's say that I have a SQLite database that I create in a separate
Let's say I have a struct with a field x that is also a
Let's say I have multiple requirements for a password. The first is that the
Let's say that I have a date in R and it's formatted as follows.
Let's say you have a method that expects a numerical value as an argument.
Let's say I have a bunch of links that share a click event: <a
Let's say that I have a html form (actually I have an editor -
Let's say that we have an ARGB color: Color argb = Color.FromARGB(127, 69, 12,

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.