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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T05:52:50+00:00 2026-05-15T05:52:50+00:00

Each time I’m writing a method that takes a boolean parameter representing an option,

  • 0

Each time I’m writing a method that takes a boolean parameter representing an option, I find myself thinking: “should I replace this by an enum which would make reading the method calls much easier?”.

Consider the following with an object that takes a parameter telling whether the implementation should use its thread-safe version or not (I’m not asking here if this way of doing this is good design or not, only the use of the boolean):

public void CreateSomeObject(bool makeThreadSafe);
CreateSomeObject(true);

When the call is next to the declaration the purpose of the parameter seems of course obvious. When it’s in some third party library you barely know, it’s harder to immediately see what the code does, compared to:

public enum CreationOptions { None, MakeThreadSafe }
public void CreateSomeObject(CreationOptions options);
CreateSomeObject(CreationOptions.MakeThreadSafe);

which describes the intent far better.

Things get worse when there’s two boolean parameters representing options. See what happened to ObjectContext.SaveChanges(bool) between Framework 3.5 and 4.0. It has been obsoleted because a second option has been introduced and the whole thing has been converted to an enum.

While it seems obvious to use an enumeration when there’s three elements or more, what’s your opinion and experiences about using an enum instead a boolean in these specific cases?

  • 1 1 Answer
  • 1 View
  • 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-15T05:52:51+00:00Added an answer on May 15, 2026 at 5:52 am

    .NET 4.0 might help here. You can use named parameters:

    CreateSomeObject(makeThreadSafe : true);
    

    For older versions it can be useful to create temporary variables instead.

    bool makeThreadSafe = true;
    CreateSomeObject(makeThreadSafe);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Each time it's time to deploy a CodeIgniter application, I find myself struggling with
I have one windows form file that each time I open it in Visual
I'd like that each time my app starts up (possibly even when it's restored
Each time I call validation method on any model, I get the following error:
Each time the save() method is called on a Django object, Django executes two
Each time i get latest version from the version control i found that the
Each time, the figure should move 1/16 of its current distance from the goal
My application gets killed each time that it comes back from the screen-off-state. I
I have some code that works each time onmouseclick and continuously onmousemove when I
Each time a python file is imported that contains a large quantity of static

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.