开发者

How to compare multiple variables in OR condition

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...

S开发者_如何学运维O is there is any other way to compare 12 variables?

Thanks Pankaj


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.


There is no way to do this.If u have this type of comarison....

Thanks

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜