Is it ok to use bitwise operator in place of a logical operator like OR

后端 未结 4 634
失恋的感觉
失恋的感觉 2021-01-26 23:55

This may be stupid.but i have a simple doubt Suppose i have the following check in a function

bool Validate(string a , string b)
{
    if(a == null || b == null)         


        
4条回答
  •  囚心锁ツ
    2021-01-27 00:39

    As has been commented upon, the code is indeed 'ok'.

    Using the single pipe '|' will evaluate all expressions before returning the result. '||' can be more efficient, since it ceases as soon as an expression evaluates to true.

提交回复
热议问题