0

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

2
  • If you have 50! nonstructured variables somehow dancing around in a method you must be doing something wrong. Maintenance of your code must be a nightmare. Isn't there any internal structure or relationship between your a,b,c,d or e etc. variables. If so then you should model that strucure in your application. Commented May 4, 2011 at 11:06
  • I'd be very curious to know in what kind of situation you would need to write such code. Maybe a little bit more context would help us do better recommandations. Commented May 4, 2011 at 18:31

2 Answers 2

1

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.

Sign up to request clarification or add additional context in comments.

Comments

0

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

Thanks

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.