views:

74

answers:

2

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 txt)
{
//do some work.
return false;
}

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

+4  A: 

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
GenericTypeTea
It's called **ampersand** btw :)
fearofawhackplanet
Yea, it's early!
GenericTypeTea
@Generic: Does it works for Javascript as well ?
Shantanu Gupta
Yes it works the same.
GenericTypeTea
+2  A: 

Just use a single bar;

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

}
C.McAtackney