New obj() vs. New obj

  • Thread starter Thread starter Erik
  • Start date Start date
E

Erik

Hi all,

I am interested in discerning the difference from my textbook and the
actual behavior of the MS Dev IDE 2003.

My textbook specifies:

objOleDbCommand = New OleDbCommand()

I type that in the VB Editor. However when I end the line and start
typing the next code line, the editor automatically removes the closing
parentheses () from end of the line so that it leaves this:

objOleDbCommand = New OleDbCommand

Any idea why this is? I wonder if this is something new in the MS Dev
Environment for version 2003.

Any time I put an arg in the the parens, then the IDE does not delete
them.

Thanks,
Erik
 
In VB.NET when instantiating a new object via its parameterless constructor
does not need the empty parethesis "()". However, using a constructor with
parameter does require them.

It's an IDE feature to remove them. I don't know the reason for that, but
they mean the same thing.
 
rmacias said:
In VB.NET when instantiating a new object via its parameterless
constructor
does not need the empty parethesis "()". However, using a constructor
with
parameter does require them.

It's an IDE feature to remove them. I don't know the reason for that, but
they mean the same thing.

The intention for automatically removing the '()' on constructor calls was
to visually disambiguish constructor calls from array declarations:

\\\
Dim a As New Object() {}
Dim b As New Object
///
 
Hi all,
I am interested in discerning the difference from my textbook and the
actual behavior of the MS Dev IDE 2003.

My textbook specifies:

objOleDbCommand = New OleDbCommand()

I type that in the VB Editor. However when I end the line and start
typing the next code line, the editor automatically removes the
closing parentheses () from end of the line so that it leaves this:

objOleDbCommand = New OleDbCommand

Any idea why this is? I wonder if this is something new in the MS Dev
Environment for version 2003.

Any time I put an arg in the the parens, then the IDE does not delete
them.

I don't have a copy with me to test, but I believe either the 2002 version
or one of it's beta versions required the (). Most likely the textbook was
written with one of these early versions and not updated when the more recent
versions were released. The reason for removing the () from the constructor
is to dis-ambiguate the type from the array version of the type.

Jim Wooley
http://devauthority.com/blogs/jwooley/default.asp
 
Ahhhhh......that make total sense now.

Herfried K. Wagner said:
The intention for automatically removing the '()' on constructor calls was
to visually disambiguish constructor calls from array declarations:

\\\
Dim a As New Object() {}
Dim b As New Object
///
 
Back
Top