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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T22:32:22+00:00 2026-06-04T22:32:22+00:00

I have a method that requires a parameter to distinguish between a few different

  • 0

I have a method that requires a parameter to distinguish between a few different scenarios. I could just pass on a string and hope that I (or whoever will use the class in future) will use one of the recognized commands. I would rather have a construct like this:

method declaration:

myMethod(myOption opt){ ... }

and the call should look like:

myMethod(myOption.option1);

in the method I should be able to do this:

if (opt == myOption.option1){ ... }

I believe this is the way the Message Box works, when I pass on the button or icon configuration.

I have experimented a lot and searched a lot, but I didn’t find anything. Maybe that is because I have not found the correct combination of keywords to feed to google.

Thanks for your help!

  • 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-04T22:32:23+00:00Added an answer on June 4, 2026 at 10:32 pm

    If you have a restricted set of available parameters, then an enum is probably the most suitable argument type to your method. So, create an enum to pass as your parameter;

    public enum MyOption
    {
        Option1,
        Option2,
        Option3,
    }
    
    public void MyMethod(MyOption option)
    {
        switch (option)
        {
            case MyOption.Option1:
                // do stuff
                return;
            case MyOption.Option2:
                // do stuff
                return;
            case MyOption.Option3:
                // do stuff
                return;
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a class that requires a specific method to be called before being
Is it possible to have a generic method that requires a delegate(?) for a
I have a method that starts like this: public static UnboundTag ResolveTag(Type bindingType, string
I have an Action that requires authentication. The action method creates some records with
If I have a method accepting a template parameter that should be convertible to,
I have a junit test method that takes a CommonsMultipartFile object as a parameter.
I have a class that have a different Add method than the other classes
I have a method that reads a random joke from a file in raw,
I have this method that usually works, but lately it has been giving me
I have a method that retrieves all data from a specific column in 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.