4 ms·
How is "Dim" worse than "var"??? In fact even before type inference I always thought that Dim was a better idea. It was kind of absurd to be forced to write yo
by cm2187 10y ago
How is "Dim" worse than "var"???
In fact even before type inference I always thought that Dim was a better idea. It was kind of absurd to be forced to write your type twice.
Dim D as New Dictionary(Of String, String)
vs
Dictionary<string, string> D = new Dictionary<string, string>();
- wvenable 10y ago> How is "Dim" worse than "var"??? Var means variable. In VB6/VBA, the Dim New syntax actually had different semantics; it would create the instance on first access instead of when the Dim statement was executed. It also had the fun side-effect that setting the variable to Nothing would destroy the instance but anytime you accessed that variable it would just create a new one. Irrelevant now, I guess, but still a nice bit of trivia.
- WayneBro 10y agoYou don't write your type twice in C# either. So, the second example would be: var d = new Dictionary<string, string>(); `Dim` is worse than `var` because nobody uses the word "Dimension" when they're talking about variables.
- cm2187 10y agoAs I said, var was introduced with type inference. Before type inference you had to declare it twice, which you never had to do in VB, even in VB6.
- WayneBro 10y agoRight, but it was introduced to C# over 8 years ago so it's a bit of a moot point, wouldn't you say? `Dim`, a poorly worded keyword by today's standards, is a perfect example of the kind of leftover crap that C# doesn't have today that VB still does have.
- smoothdeveloper 10y agoTry defining an instance member with var in C#