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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T09:07:30+00:00 2026-05-16T09:07:30+00:00

I have this if statement – if (!((main.property == 1)||(main.property == 2))) { …

  • 0

I have this if statement –

if (!((main.property == 1)||(main.property == 2)))
{
   ...
}

main.property is a byte which is either 0, 1, 2 or 98.

Visual studios says that this statement is always true but I can’t see why?

If the property is 1 or 2 shouldn’t this be false.

Thank you in advance.

Edit: Added code

file1.cs

private void Upload(DataSet ds)
{
    Main main = CreateMain(ds); //This is tested and works correctly
    if(ValidateDate(main))
    {
        ...
    }
}

file2.cs

internal static bool ValidateData(Main main, ...)
{
    if (!((main.property == 1)||(main.property == 2)))
    {
        ...
    }
}

Edit: Added code

If I do this the error goes away –

internal static bool ValidateData(Main main, ...)
{
     main.property = 0; //Or = any number
     if (!((main.property == 1)||(main.property == 2)))
     {
          ...
     }
}

I’m guessing VS thinks it isn’t initialised but I am 100% positive it is.

  • 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-16T09:07:31+00:00Added an answer on May 16, 2026 at 9:07 am

    I wrote this little program to check it out:

        class Program
    {
        static void Main(string[] args)
        {
            test(0);
            test(1);
            test(2);
            test(3);
            Console.ReadLine();
        }
    
        private static void test(int p)
        {
            bool b1 = (!((p == 1) || (p == 2)));
            bool b2 = (p != 1 && p != 2);
            Console.Out.WriteLine("{0} {1} {2}", b1, b2, b1 == b2);
        }
    }
    

    It seems that Constantin is right in his transcription, but neither expression is always true or always false.

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

Sidebar

Related Questions

I currently have this statement in my SQL View (SQL Server 2008 R2) which
I have this if statement that tests for the 2 conditions below. The second
I have this statement: String cap = Regex.Replace(winCaption, @[^\w\.@-], ); that transforms Hello |
I have this statement: Assume the bit value of byte x is 00101011. what
I have this statement which is the wrong way to do it but how
I have this if statement, which returns the result as a AsQueryable to an
In Python I have this statement: blog_ids = [c.blog_id for c in connections] Which
I have this statement: SELECT passwdlib.piv_insertPasswd(:A1, :A2) FROM DUAL I am guessing that piv_insertPasswd
I have this statement that im trying to figure out how to use in
I have this select statement that selects all of the child nodes of what

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.