Q on brackets after instantiation

  • Thread starter Thread starter Eric Sabine
  • Start date Start date
E

Eric Sabine

I came across this line of code:

Dim arParms() As System.Data.SqlClient.SqlParameter = _
New System.Data.SqlClient.SqlParameter(3) {}

and am a bit confused because the New() method of the SqlParameter class
doesn't have a signature for only 1 input value. It has

New()
New(ByVal String, ByVal Object)
New(ByVal String, ByVal System.Data.SqlDbType)
New(ByVal String, ByVal System.Data.SqlDbType, ByVal Integer)
New(ByVal String, ByVal System.Data.SqlDbType, ByVal Integer, ByVal String)

But what follows the instantiation is to curly brackets, i.e., {}. So
logically if I comment out the 2 curly brackets at the end I get a syntax
error. Can someone explain to me what the "{}" does?

Thanks, Eric
 
* "Eric Sabine said:
I came across this line of code:

Dim arParms() As System.Data.SqlClient.SqlParameter = _
New System.Data.SqlClient.SqlParameter(3) {}

and am a bit confused because the New() method of the SqlParameter class
doesn't have a signature for only 1 input value. It has

New()
New(ByVal String, ByVal Object)
New(ByVal String, ByVal System.Data.SqlDbType)
New(ByVal String, ByVal System.Data.SqlDbType, ByVal Integer)
New(ByVal String, ByVal System.Data.SqlDbType, ByVal Integer, ByVal String)

But what follows the instantiation is to curly brackets, i.e., {}. So
logically if I comment out the 2 curly brackets at the end I get a syntax
error. Can someone explain to me what the "{}" does?

The curly brackets are used to indicate that an array should be created,
instead of instantiating a class (calling the ctor).
 
ACK. Thank you.

ctor = constructor ?


Herfried K. Wagner said:
The curly brackets are used to indicate that an array should be created,
instead of instantiating a class (calling the ctor).
 
Back
Top