Alex Rivera | Logout

C# 'or' operator?

Asked 2009-11-17T02:56:28.117
37

Is there an or operator in C#?

I want to do:

if (ActionsLogWriter.Close or ErrorDumpWriter.Close == true)
{
    // Do stuff here
}

But I'm not sure how I could do something like that.

c#
Edit
Report

2 Answers

105

C# supports two boolean or operators: the single bar | and the double-bar ||.

The difference is that | always checks both the left and right conditions, while || only checks the right-side condition if it's necessary (if the left side evaluates to false).

This is significant when the condition on the right-side involves processing or results in side effects. (For example, if your ErrorDumpWriter.Close method took a while to complete or changed something's state.)

answered 2009-11-17T03:00:41.060
2

Or is || in C#.

You may have a look at this.

answered 2009-11-17T02:58:34.030

Your Answer