473,396 Members | 2,009 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Syntax Question

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
14 1190
"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
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
* "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
"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
* "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
"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
* "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
"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
* "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
"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
* "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
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
"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
* "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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

699
by: mike420 | last post by:
I think everyone who used Python will agree that its syntax is the best thing going for it. It is very readable and easy for everyone to learn. But, Python does not a have very good macro...
4
by: Aaron Walker | last post by:
Greetings, I'm attempting to write my first *real* template function that also deals with a map of strings to member function pointers that is making the syntax a little tricky to get right. ...
2
by: bor_kev | last post by:
Hi, First of all, i want to use the new managed class syntax and STL.NET under Microsoft Visual (C++) Studio 2005 Beta. I read in a Microsoft...
5
by: r.nikhilk | last post by:
Hi, Currently, we are porting C++ applications from 32 bit to 64 bit on AIX platform. (The current version of AIX is 5.3 and xlC verison is 8.0). We are able to compile the applications by...
3
by: astromog | last post by:
I have some significantly extended syntax for Python that I need to create a reference implementation for. My new syntax includes new keywords, statements and objects that are sort of like classes...
11
by: deppy_3 | last post by:
Hi! The syntax of fputs() is similar with the syntax of fgets(); For example if we have:fgets(str,maxlen,stdin) which is the syntax of the fputs();
8
by: Smithers | last post by:
Are there any important differences between the following two ways to convert to a type?... where 'important differences' means something more profound than a simple syntax preference of the...
2
by: berrylthird | last post by:
This question was inspired by scripting languages such as JavaScript. In JavaScript, I can access members of a class using array syntax as in the following example: var myInstance:myClass = new...
17
by: trose178 | last post by:
Good day all, I am working on a multi-select list box for a standard question checklist database and I am running into a syntax error in the code that I cannot seem to correct. I will also note...
6
by: Daniel | last post by:
I hope this question is OK for this list. I've downloaded Rpyc and placed it in my site packages dir. On some machines it works fine, on others not so much. Here is one error I get when I try...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.