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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T20:37:13+00:00 2026-05-28T20:37:13+00:00

I’m reading an source code, I found a statement like this: if (Char.IsWhiteSpace(text[i]) |

  • 0

I’m reading an source code, I found a statement like this:

if (Char.IsWhiteSpace(text[i]) | GetSpecialChars.Contains(text[i]))

Initially,I thought it was typo,instead || (or) operator. But for my surprise, it was compiled. how to it’s possible? is | equivalent to || with boolean types?

Thanks in advance.

  • 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-28T20:37:14+00:00Added an answer on May 28, 2026 at 8:37 pm

    I’d suggest that it probably is a typo, though it will still work.

    The reason boolean | is so rarely seen is that:

    1. Much of the time || is the only one that is correct. If the expression on the right hand side would throw if the expression on the left-hand was true such as in x == null || x.Length == 0 which would successfully return true for a null or zero-length string or array while x == null | x.Length == 0 which would throw an exception for a null string or array as the Length property would still be examined.
    2. Most of the rest of the time || will be faster. It might be nothing but a couple of clock cycles faster (though it could also be more if the expression on the rhs is expensive), but it hardly counts as a premature optimisation that we’re all in the habit of using that form. (Just how much effort you put into deciding which goes on the left and which on the right may be another matter).
    3. Some constructs that use it by one-line fans are rather unclear as far as readabilty goes.

    The example in the question falls under point two. The only effect of | rather than || here in practice is a few nanoseconds of waste. Not that it matters, but it does lead to || being the habit to fall into.

    (If on the other hand a property called GetSpecialChars or a method called Contains has a side-effect that means it has to be called, that property really needs to be renamed to make it clearer!).

    About the only time it’s useful is either because we really need some side-effect of the right-hand expression to take place, or in the assignment form based on it, |=.

    In the former case, it’s always worth considering an alternative of evaluating both expressions in separate statements and then ORing the result afterwards, to make it clearer that you care about the side-effect as well as the result.

    In the latter case, it can make for more readable code, or at least to code that’s more readable to some people! But many find it obscures things.

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

Sidebar

Related Questions

For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
I have some data like this: 1 2 3 4 5 9 2 6
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I would like to count the length of a string with PHP. The string
this is what i have right now Drawing an RSS feed into the php,
I've got a string that has curly quotes in it. I'd like to replace
We are using XSLT to translate a RIXML file to XML. Our RIXML contains

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.