Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to use both && and || in the same if statement condition?

I can’t seem to figure out how to use || and && in the same if statement ‘and, or’ being keywords for google it wasn’t really easy to google i got something like this

this.Hide();

if (txt_Password.Text == "karasumyo2022" && txt_UserName.Text == "whatever" || "somethingelse"  )
{
    new Form1().Show();
    this.Hide();
}

any ideas?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You can use something like this by making use of brackets:

if (txt_Password.Text == "karasumyo2022" &&
   (txt_UserName.Text == "whatever" || txt_UserName.Text == "somethingelse" ))
// ^                                                                        ^
{
    new Form1().Show();
    this.Hide();
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading