This article is a mirror article of machine translation, please click here to jump to the original article.

View: 5078|Reply: 2

[Source] .NET/C# uses the && distinction in IF judgments

[Copy link]
Posted on 2023-2-9 19:57:08 | | | |
When I was chatting with my colleague, my colleague suddenly asked me what was the difference between using one & and two && symbols in IF judgment, and I was suddenly confused, forgetting whether to use one & symbol as and condition, or two && symbols as and conditions.Correct is in IF logic judgment and is using two && symbols

Bit operators are faster than ordinary arithmetic operators, and can perform some functions that arithmetic operators cannot. If you want to develop efficient programs, bit operators are essential. Bit operators are used to manipulate binary bits, including: bitwise and (&), bitwise or (|), bitwise or (^), bitwise inverse (~), bitwise shift (<<), bitwise shift (>>).

& is bitwise and, meaning it works at the bit level. && is a logical with, meaning it works at the Boolean (true/false) level. Logic and the use of short circuits (If the first part is false, it is useless to check the second part) to prevent running too much code,And by bit and need to operate on each bit to determine the result


The sample code is as follows:



It can be seen that when using the && symbol, if the first one is false, the second judgment will not be executed, while when using the & symbol, although the first one is false, the obvious result must be false, but the second judgment method will still be executed.

(End)




Previous:Use PowerShell commands to clone the IIS app pool
Next:Ventoy solution for USB flash drive mounting system
Posted on 2023-2-9 23:24:41 |
Learn to learn
Posted on 2023-2-27 14:42:57 |
Learn, learn, learn, learn, learn
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com