It isn't intended to torture but rather it is the result of having to
conform new language features into a system not originally designed to
accomodate such things. There is a bit of "VB-ism" concern but consider the
challenge.
The following (not withstanding my belief that "dim" as a keyword is
outdated (somebody will surely defend it I'm certain)) 1) declares the
scope of the variable, 2) defines it's datatype and 3) assigns a value (the
object reference.)
Dim x as Control = New Control()
While the following works it is generally a syntactical shortcut and I
recommend you avoid it. As always my recommendation is to avoid
language-specific items and to embrace language-agnostic solutions (when it
is possible and practical to do so). Those intent on arguing please re-read
the stuff in parens :-)
Dim x As New Control
Part of the reason is that it doesn't follow that you want a "control"
reference just because you instantiate a control object. The following
works as well because an ArrayList is in fact an object. The shortcut
version cannot do this.
Dim obj As Object
obj = New ArrayList()
So now consider how does one assign contant values? The following works:
Dim arg As String
arg = "test"
Note also that you aren't particularly bothered by the lack of a New keyword
in this instance, right? I'll suggest you've grown accustomed to thinking
of strings as some sort of natural computer data type but they aren't. :-)
So what would the syntax be to assign constant array values? An array
requires the New keyword and that means you have to include the class name
and only then can you tack on the values you want. So you end up with
something like the following:
Dim args As String()
args = New String() {"test"}
Here it is as an array of Integers:
Dim arr As Integer()
arr = New Integer() {1, 2, 3}
So what's left is the example you saw originally, the declaration and
assignment of an array of Objects.
Dim args as Object()
args = New Object() { strtext }
And that's why we have that syntax. What else could the syntax be and do
you think another one would be more clear?
Tom
"Zytan" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
>> There is no difference. The second is just a short form for the first
>> one that is available when you are declaring the variable and assigning
>> a value to it in the same statement.
>
> Is this done to torture newbies? 
>
> I just dont follow how an acceptable way of shortening code allows the
> removal of the "New" keyword. Am i the only one who is bothered by
> this? Is there any other meaningful way i can think of this style of
> code that *makes sense*, in that i can think that "New" really is
> there? I just can't wrap my mind around it. for example I can see
> how this:
>
> Dim x As Control = New Control
>
> it shortened to this:
>
> Dim x As New Control
>
> But, for:
>
> Dim args As Object() = New Object() {strText}
>
> shortened to this:
>
> Dim args As Object() = {strText}
>
> doesn't flow. What am i not seeing?
>
>> If you first declare the variable and then assign a value to it, you
>> have to specify the type of the value:
>>
>> Dim args as Object()
>> args = New Object() { strtext }
>>
>> ' this would produce a compiler error
>> ' args = { strtext }
>
> yes, ok. thanks.
>
> And this strengthens my perspecitve in that the shortening doesn't
> 'flow'. It doesn't seem as though it should work. Do you follow what
> i'm saying?
>
> Zytan
>
>