By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,414 Members | 1,050 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,414 IT Pros & Developers. It's quick & easy.

Syntax Question

P: n/a
The company I am working for is trying to work with the Application
Data Blocks that Microsoft released to provide transparent database
connectivity for our .NET applications. I have been tasked with having
a thorough understanding of the code. However, while wading through
the source, I came across a section of code that does not make sense
to me. I was hoping that someone here would be able to enlighten me.
The code in question is in the SqlDbHelper.vb file and is under the
DiscoverSpParameterSet function:

Dim cn As New SqlConnection(connectionString)
Dim cmd As SqlCommand = New SqlCommand(spName, cn)
Dim discoveredParameters() As IDataParameter

Try
cn.Open()
cmd.CommandType = CommandType.StoredProcedure
SqlCommandBuilder.DeriveParameters(cmd)
If Not includeReturnValueParameter Then
cmd.Parameters.RemoveAt(0)
End If

discoveredParameters = New SqlParameter(cmd.Parameters.Count - 1)
{}
cmd.Parameters.CopyTo(discoveredParameters, 0)
Finally
cmd.Dispose()
cn.Dispose()
End Try

The line I am not understanding is:

discoveredParameters = New SqlParameter(cmd.Parameters.Count - 1) {}

I can see that an instance of a SqlParameter object is being created.
However, none of the overloaded constructors match the arguments
given. Though at the end of the statement are an opening and closing
curly brace ({}). If this is removed, I do indeed get the expected
error that I just mentioned. However, with these curly braces,
everything is fine. What is being accomplished here? Thanks in advance
for any insight you can provide.

Robert
Nov 20 '05 #1
Share this Question
Share on Google+
14 Replies


P: n/a
"Robert Brinson" <rb******@cox-internet.com> schrieb
The line I am not understanding is:

discoveredParameters = New SqlParameter(cmd.Parameters.Count - 1)
{}

I can see that an instance of a SqlParameter object is being
created. However, none of the overloaded constructors match the
arguments given. Though at the end of the statement are an opening
and closing curly brace ({}). If this is removed, I do indeed get the
expected error that I just mentioned. However, with these curly
braces, everything is fine. What is being accomplished here? Thanks
in advance for any insight you can provide.

I (also) think this is a language inconsistency:

'creates a new instance of <type>, passing <args> to the ocnstructor.
var = New <type>(<args>)

'creates an *array* of <type>, upper bound is <args>, no items are put in
the
array:
var = new <type>(<args>){}

'creates an *array* of <typeY, upper bound is <args>, one item is put in the
array:
var = new <type>(<args>){<Item>}

--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html

Nov 20 '05 #2

P: n/a
Cor
Hi Robert,

I waited on Armin, because he had a long arguing about this empty string
last week.

But if I was you I did put this message also it in the
public.dotnet.framework.adonet newsgroup.

A lot of those who are active in that newsgroup knows especialy much from
the parameters, which are less used by the more VB.language affected people.

Then with the answers from 2 directions I think you have the best response.

Cor
Nov 20 '05 #3

P: n/a
* "Armin Zingler" <az*******@freenet.de> scripsit:
I can see that an instance of a SqlParameter object is being
created. However, none of the overloaded constructors match the
arguments given. Though at the end of the statement are an opening
and closing curly brace ({}). If this is removed, I do indeed get the
expected error that I just mentioned. However, with these curly
braces, everything is fine. What is being accomplished here? Thanks
in advance for any insight you can provide.
I (also) think this is a language inconsistency:


Please point out what's "inconsistent" behavior...
'creates a new instance of <type>, passing <args> to the ocnstructor.
var = New <type>(<args>)

'creates an *array* of <type>, upper bound is <args>, no items are put in
the
array:
var = new <type>(<args>){}

'creates an *array* of <typeY, upper bound is <args>, one item is put in the
array:
var = new <type>(<args>){<Item>}


--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #4

P: n/a
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schrieb
* "Armin Zingler" <az*******@freenet.de> scripsit:
I can see that an instance of a SqlParameter object is being
created. However, none of the overloaded constructors match the
arguments given. Though at the end of the statement are an
opening and closing curly brace ({}). If this is removed, I do
indeed get the expected error that I just mentioned. However, with
these curly braces, everything is fine. What is being accomplished
here? Thanks in advance for any insight you can provide.


I (also) think this is a language inconsistency:


Please point out what's "inconsistent" behavior...


As stated in the previous thread:

Me:
New Form 'create new form
New Form(10) 'create new form + call param. ctor
New Form(10){} 'create new form + call param. ctor + assign empty array

You:
In the last line: Why should it call the ctor?

Me:
For the same reason as in the 2nd line.
You didn't reply to my last statement. ;-)

--
Armin

Nov 20 '05 #5

P: n/a
* "Armin Zingler" <az*******@freenet.de> scripsit:
I can see that an instance of a SqlParameter object is being
created. However, none of the overloaded constructors match the
arguments given. Though at the end of the statement are an
opening and closing curly brace ({}). If this is removed, I do
indeed get the expected error that I just mentioned. However, with
these curly braces, everything is fine. What is being accomplished
here? Thanks in advance for any insight you can provide.

I (also) think this is a language inconsistency:
Please point out what's "inconsistent" behavior...


As stated in the previous thread:

Me:
New Form 'create new form
New Form(10) 'create new form + call param. ctor
New Form(10){} 'create new form + call param. ctor + assign empty array


The last line doesn't call the parameterized ctor. It creates an array
with 11 elements, all pointing to 'Nothing'.
You:
In the last line: Why should it call the ctor?

Me:
For the same reason as in the 2nd line.


LOL, but where to insert the element?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #6

P: n/a
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schrieb
Please point out what's "inconsistent" behavior...


As stated in the previous thread:

Me:
New Form 'create new form
New Form(10) 'create new form + call param. ctor
New Form(10){} 'create new form + call param. ctor + assign empty
array


The last line doesn't call the parameterized ctor. It creates an
array with 11 elements, all pointing to 'Nothing'.


Right, in opposite to the 2nd line the 3rd line creates an array. That's the
inconsistence you were asking for.
You:
In the last line: Why should it call the ctor?

Me:
For the same reason as in the 2nd line.


LOL, but where to insert the element?


Which element? A Form does not need an element.
--
Armin

Nov 20 '05 #7

P: n/a
* "Armin Zingler" <az*******@freenet.de> scripsit:
As stated in the previous thread:

Me:
New Form 'create new form
New Form(10) 'create new form + call param. ctor
New Form(10){} 'create new form + call param. ctor + assign empty
array


The last line doesn't call the parameterized ctor. It creates an
array with 11 elements, all pointing to 'Nothing'.


Right, in opposite to the 2nd line the 3rd line creates an array. That's the
inconsistence you were asking for.


That's IMO not inconsistent. "(", ")" have multiple semantics in VB.NET,
the "{}" tells VB.NET to interpret the "(", ")" as array bound specifier
brackets.
You:
In the last line: Why should it call the ctor?

Me:
For the same reason as in the 2nd line.


LOL, but where to insert the element?


Which element? A Form does not need an element.


If the last version listed above would call the ctor too, where would
you expect this object to be inserted in the array?

\\\
Dim f() As Form = New Form(10) {}
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #8

P: n/a
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schrieb
* "Armin Zingler" <az*******@freenet.de> scripsit:
As stated in the previous thread:

Me:
New Form 'create new form
New Form(10) 'create new form + call param. ctor
New Form(10){} 'create new form + call param. ctor + assign
empty array

The last line doesn't call the parameterized ctor. It creates
an array with 11 elements, all pointing to 'Nothing'.


Right, in opposite to the 2nd line the 3rd line creates an array.
That's the inconsistence you were asking for.


That's IMO not inconsistent. "(", ")" have multiple semantics in
VB.NET, the "{}" tells VB.NET to interpret the "(", ")" as array
bound specifier brackets.


I consider the ambiguous interpretation of the "()" to be inconsistent. The
"{}" are optional:

new form(10)[array-initializer]

You:
In the last line: Why should it call the ctor?

Me:
For the same reason as in the 2nd line.

LOL, but where to insert the element?


Which element? A Form does not need an element.


If the last version listed above would call the ctor too, where
would you expect this object to be inserted in the array?

\\\
Dim f() As Form = New Form(10) {}
///


As "New Form(10){}" doesn't make sense, the whole line doesn't, so I can't
answer the question.

All IMO.
--
Armin

Nov 20 '05 #9

P: n/a
* "Armin Zingler" <az*******@freenet.de> scripsit:
> Me:
> New Form 'create new form
> New Form(10) 'create new form + call param. ctor
> New Form(10){} 'create new form + call param. ctor + assign
> empty array

The last line doesn't call the parameterized ctor. It creates
an array with 11 elements, all pointing to 'Nothing'.

Right, in opposite to the 2nd line the 3rd line creates an array.
That's the inconsistence you were asking for.


That's IMO not inconsistent. "(", ")" have multiple semantics in
VB.NET, the "{}" tells VB.NET to interpret the "(", ")" as array
bound specifier brackets.


I consider the ambiguous interpretation of the "()" to be inconsistent. The
"{}" are optional:

new form(10)[array-initializer]


That's how _you_ interpret it.
LOL, but where to insert the element?

Which element? A Form does not need an element.


If the last version listed above would call the ctor too, where
would you expect this object to be inserted in the array?

\\\
Dim f() As Form = New Form(10) {}
///


As "New Form(10){}" doesn't make sense, the whole line doesn't, so I can't
answer the question.


You would forbid this syntax?

;->

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #10

P: n/a
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schrieb
Right, in opposite to the 2nd line the 3rd line creates an
array. That's the inconsistence you were asking for.

That's IMO not inconsistent. "(", ")" have multiple semantics
in VB.NET, the "{}" tells VB.NET to interpret the "(", ")" as
array bound specifier brackets.


I consider the ambiguous interpretation of the "()" to be
inconsistent. The "{}" are optional:

new form(10)[array-initializer]


That's how _you_ interpret it.


Yes, but if I'd interpret it the way VB does, it is ambiguous. It is
ambiguous because the "()" brackets can be interpreted this or that way.

\\\
Dim f() As Form = New Form(10) {}
///


As "New Form(10){}" doesn't make sense, the whole line doesn't, so I can't answer the question.


You would forbid this syntax?


Yes
....and: no, I currently can't offer an alternative. ;-)

--
Armin

Nov 20 '05 #11

P: n/a
* "Armin Zingler" <az*******@freenet.de> scripsit:
> Right, in opposite to the 2nd line the 3rd line creates an
> array. That's the inconsistence you were asking for.

That's IMO not inconsistent. "(", ")" have multiple semantics
in VB.NET, the "{}" tells VB.NET to interpret the "(", ")" as
array bound specifier brackets.

I consider the ambiguous interpretation of the "()" to be
inconsistent. The "{}" are optional:

new form(10)[array-initializer]


That's how _you_ interpret it.


Yes, but if I'd interpret it the way VB does, it is ambiguous. It is
ambiguous because the "()" brackets can be interpreted this or that way.


;-)
\\\
Dim f() As Form = New Form(10) {}
///

As "New Form(10){}" doesn't make sense, the whole line doesn't, so I can't answer the question.


You would forbid this syntax?


Yes

...and: no, I currently can't offer an alternative. ;-)


Maybe "[", "]" for arrays?

SCNR

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #12

P: n/a
Cor
Hi Armin and Herfried,

This discussion has been done, I was very short involved, I thought that the
outcoming was something on a suggestion from Jay B. (on a sentence that I
made conform what Armin is saying now) that this code should be possible but
not be prefered.

As you probably know, I like multiple possibilities in code so I did agree
with him, although I find it stupid code.

Cor
Nov 20 '05 #13

P: n/a
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schrieb
Yes, but if I'd interpret it the way VB does, it is ambiguous. It
is ambiguous because the "()" brackets can be interpreted this or
that way.


;-)


gotcha! ;-))
You would forbid this syntax?


Yes

...and: no, I currently can't offer an alternative. ;-)


Maybe "[", "]" for arrays?

SCNR


NO!

;-)

Well, EOT... :-)
--
Armin

Nov 20 '05 #14

P: n/a
* "Cor" <no*@non.com> scripsit:
This discussion has been done, I was very short involved, I thought that the
outcoming was something on a suggestion from Jay B. (on a sentence that I
made conform what Armin is saying now) that this code should be possible but
not be prefered.
.... and I don't agree with that.
As you probably know, I like multiple possibilities in code so I did agree
with him, although I find it stupid code.


;-)

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #15

This discussion thread is closed

Replies have been disabled for this discussion.