Is it in VB.NET possible to use variables without the need of use DIM?
now I have to use the variables like this:
dim a = 100
dim b = 50
dim c = a + b
I want to be able to use vars in this way:
a=100
b=50
c=a+b 'c contains 150
I think in VB6 and older VB this was possible, but I am not sure.
As far as what @Konrad said, he is correct. The answer, buried in all his caveat emptors, is the answer of “yes”, you can absolutely do this in VB.NET by declaring
Option Explicit Off. That said, when you doa=1, the variableais NOT anInteger– it is anObjecttype. So, you can’t then doc = a + bwithout compiler errors. You’ll need to also declareOption Strict Off. And at that point, you throw away all the benefits of a compiler. Don’t do it.As an alternative, with
Option Infer On,Dimbehaves the same as C#’svarkeyword and gives you a lot of advantages if you’re trying to save on typing.