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 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
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
* "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>
"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
* "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>
"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
* "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>
"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
* "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>
"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
* "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>
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
"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
* "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> This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
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...
|
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.
...
|
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...
|
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...
|
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...
|
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();
|
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...
|
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...
|
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...
|
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...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
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...
|
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
|
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...
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
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,...
|
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...
|
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...
|
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,...
| |