How to avoid short circuit evaluation in C# while doing the same functionality

前端 未结 2 1215
你的背包
你的背包 2020-12-20 12:30

Do we have any operator in C# by which I can avoid short circuit evaluation and traverse to all the conditions.

say

if(txtName.Text.xyz() || txtLas         


        
相关标签:
2条回答
  • 2020-12-20 12:55

    Just use a single bar;

    if(txtName.Text.xyz() | txtLName.Text.xyz())
    {
    
    }
    
    0 讨论(0)
  • 2020-12-20 12:58

    Just use a single bar, this will evaluated both arguments regardless of the outcome of the first result.

    if(txtName.Text.xyz() | txtLastName.Text.xyz()) { }
    

    You can also do the same with AND, i.e. You can replace && with a single ampersand to get the same affect as above:

    if(txtName.Text.xyz() & txtLastName.Text.xyz()) { } // Both sides will be called
    
    0 讨论(0)
提交回复
热议问题