Maya
Maya

Reputation: 7223

Continuing code in next line

if (some condition) || 
(some other condition)
{
   // do something
}

The above format does not work. Says invalid expression "||".

Upvotes: 2

Views: 2304

Answers (3)

BrokenGlass
BrokenGlass

Reputation: 160982

your brackets are off, should be:

if ((some condition) || 
(some other condition))
{
   // do something
}

Upvotes: 5

George Johnston
George Johnston

Reputation: 32278

You're missing outside parentheses on your if statement. e.g.

if ((some condition) || (some other condition))
{ 
   // do something 
}

Upvotes: 7

Daniel DiPaolo
Daniel DiPaolo

Reputation: 56408

if statements in C# need to be entirely contained in a set of parentheses. Add another set around your two ||ed expressions and that will work fine, even on two lines.

if ((some condition) ||
    (some other condition))
{
    // do something
}

Upvotes: 8

Related Questions