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

  • Home
  • SEARCH
  • 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 6998579
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T20:25:45+00:00 2026-05-27T20:25:45+00:00

I have a if condition for a Enum. My enum is : public enum

  • 0

I have a if condition for a Enum. My enum is :

public enum EmploymentType
{
   Type1 = 1,
   Type2 = 2,
   Type3 = 3
}

and this condition

EmploymentType type = EmploymentType.Type1 ;

if (type.HasFlag(EmploymentType.Type1 | EmploymentType.Type2 )) //if (type == (EmploymentType.Type1 | EmploymentType.Type2 ))
{
    return true;
}
else
{
    return false;
}

Expected true result for this condition, but result is false. Why?

  • 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-27T20:25:46+00:00Added an answer on May 27, 2026 at 8:25 pm

    There’s a few things you are doing wrong here:

    • Your enumeration does not have the [Flags] attribute. HasFlags is designed to work only with enumerations with this attribute set.

    • You don’t follow the flag conventions. Unless Type3 is a combination of Type1 and Type2, it should have value 4 instead of 3. Read up on the documentation in the FlagsAttribute MSDN page.

    • Your expectations are wrong: HasFlag(Flag1 | Flag2) returns only true of both Flag1 and Flag2 are set, since you are bitwise OR-ing Flag1 and Flag2 and checking if these bits are set. Please have a look at the HasFlag documentation for details.

    I suspect that your enum is meant to be just an enum and not a container for flags. Flags are supposed to be combinable, i.e., type could be “Type1 and Type2” or “no type” or “all types” (like font formatting, which can be “none”, “bold”, “italic” as well as “bold and italic”, “bold and underlined”, etc.). I don’t think that applies to your case.

    So, forget about the flags thing and just use regular enum matching (such as type == EmploymentType.Type1 || type == EmploymentType.Type2 or a switch statement) instead of the HasFlags method.

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

Sidebar

Related Questions

If I have the following enum type: typedef enum {Type1=0, Type2, Type3} EnumType; And
I have this, public enum Condition : uint // bitwise { None = 0,
I have this If condition in VB6 If ( X AND ( 2 ^
i have a class and have declared an enum in it like public enum
I have declared the following enum type in which I want the first member
I have this condition: If (cmbStatusSearch.SelectedValue <> -1) Then How can I make it
I have defined an enum like this: enum blStatus { Class1 = 0x40, /*
I have an enum, that looks like this: enum Suit {Clubs, Diamonds, Hearts, Spades};
I have a condition in which I need to close the application and so
I have a condition in a silverlight application that compares 2 strings, for some

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.