开发者

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

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() || txtLastName.Text.xyz())
{

}

public static bool xyz(this TextBox t开发者_如何学编程xt)
{
//do some work.
return false;
}

It should evaluate all conditions irrespective of output obtained. And after evaluating last condition continues according to result obtained. ?


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


Just use a single bar;

if(txtName.Text.xyz() | txtLName.Text.xyz())
{

}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜