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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T19:56:32+00:00 2026-05-10T19:56:32+00:00

Of the two methods below, which do you prefer to read? Is there another

  • 0

Of the two methods below, which do you prefer to read?
Is there another (better?) way to check if a flag is set?

 bool CheckFlag(FooFlag fooFlag)  {       return fooFlag == (this.Foo & fooFlag);  } 

And

 bool CheckFlag(FooFlag fooFlag)  {       return (this.Foo & fooFlag) != 0;  } 

Please vote up the method you prefer.

  • 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. 2026-05-10T19:56:33+00:00Added an answer on May 10, 2026 at 7:56 pm

    The two expressions do different things (if fooFlag has more than one bit set), so which one is better really depends on the behavior you want:

    fooFlag == (this.Foo & fooFlag) // result is true iff all bits in fooFlag are set   (this.Foo & fooFlag) != 0       // result is true if any bits in fooFlag are set 
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given below are two methods which create a delegate to set a field in
I have two methods below. One method ( timerHit ) which gets the track
I have a Controller with two Edit methods (see below). When I submit the
I know of two methods which are not reliable: _access() - doesn't work on
There are two different methods to declare IBOutlet. In @interface section as variable: IBOutlet
I have two methods, ProcessQueue and AddToQueue , which happen on different threads. Sometimes
Out of the below two synchronization strategy, which one is optimized (as in processing
We're trying to connect with another company's custom API which uses two-legged OAuth to
The two methods below each serve the same purpose: scan the content of the
These two methods exhibit repetition: public static Expression<Func<Foo, FooEditDto>> EditDtoSelector() { return f =>

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.