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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T14:12:48+00:00 2026-05-10T14:12:48+00:00

I have always used || (two pipes) in OR expressions, both in C# and

  • 0

I have always used || (two pipes) in OR expressions, both in C# and PHP. Occasionally I see a single pipe used: |. What is the difference between those two usages? Are there any caveats when using one over the other or are they interchangeable?

  • 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-10T14:12:48+00:00Added an answer on May 10, 2026 at 2:12 pm

    Just like the & and && operator, the double Operator is a ‘short-circuit’ operator.

    For example:

    if(condition1 || condition2 || condition3) 

    If condition1 is true, condition 2 and 3 will NOT be checked.

    if(condition1 | condition2 | condition3) 

    This will check conditions 2 and 3, even if 1 is already true. As your conditions can be quite expensive functions, you can get a good performance boost by using them.

    There is one big caveat, NullReferences or similar problems. For example:

    if(class != null && class.someVar < 20) 

    If class is null, the if-statement will stop after class != null is false. If you only use &, it will try to check class.someVar and you get a nice NullReferenceException. With the Or-Operator that may not be that much of a trap as it’s unlikely that you trigger something bad, but it’s something to keep in mind.

    No one ever uses the single & or | operators though, unless you have a design where each condition is a function that HAS to be executed. Sounds like a design smell, but sometimes (rarely) it’s a clean way to do stuff. The & operator does ‘run these 3 functions, and if one of them returns false, execute the else block’, while the | does ‘only run the else block if none return false’ – can be useful, but as said, often it’s a design smell.

    There is a Second use of the | and & operator though: Bitwise Operations.

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

Sidebar

Related Questions

I am needing date pickers for two cases, so far I have always used
I have always used the mouseover event, but while reading the jQuery documentation I
As a hardcore WinForms programmer from a Win32 background I have always used Spy++
I have generally always used some sort of Hungarian Notation for my field names
I always have used Spring Framework classes as-is. However I am thinking of customizing
I have a C program which has always used hard coded define statements for
We have used Infragistics controls in our applications for years. However, we have always
I have java sdk 1.7. I've always used django/python for web development, this will
I have a data frame with two columns (data will not always be identical).
I have always used mod_rewrite for creating clean looking URLs, until recently I didn’t

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.