Reputation: 589
I have 12 variables in VB.Net.
If a = 1 _ Or b = 2 _ Or c = 3 _ Or d = 4 _ Or e = 5 _ Or f = 6 _ Or...... Then
Like That....
For that my string will be so long for 12 variables...
SO is there is any other way to compare 12 variables?
Thanks Pankaj
Upvotes: 0
Views: 1970
Reputation: 589
There is no way to do this.If u have this type of comarison....
Thanks
Upvotes: 0
Reputation: 57939
There are a number of ways to compare a bunch of variables to a single value or evaluate an expression against them. For example if you wanted to check whether any of your variables a through z equal 10.
When you are evaluating each of them against a different constant value, however, you need the expression for each one.
You should note that your code will unnecessarily evaluate all of the expressions, when in theory it could stop checking once any of the conditions are met. For that, use OrElse
instead of Or
. That will, of course, make the code even longer.
One way to pare down the syntax slightly (for long condition sets):
Dim all = new Boolean(){ _
a = 1, _
b = 2, _
c = 3, _
d = 4, _
e = 5, _
}.All(Function(x As Boolean) x)
This again, however, results in evaluation of all conditions.
Upvotes: 1