473,378 Members | 1,441 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,378 software developers and data experts.

{} again

Hei
Hi All

in the book of example :

Public MustInherit Class Broker

Private const m_MAXRESERVATION As Integer =10
Protected m_reservations() as Reservation

Public Sub New()
m_reservations = New Reservation(m_MAXRESERVATION ) {}

End Sub

......

what mean of {} in above case?

thx
Hei

Nov 20 '05 #1
27 1222
The code is creating an array. Look in the VB language reference, near the
end of the Dim topic there's an explanation for that.
--
____________________
Klaus H. Probst, MVP
http://www.vbbox.com/

"Hei" <ch******@msn.com> wrote in message
news:eq**************@TK2MSFTNGP12.phx.gbl...
Hi All

in the book of example :

Public MustInherit Class Broker

Private const m_MAXRESERVATION As Integer =10
Protected m_reservations() as Reservation

Public Sub New()
m_reservations = New Reservation(m_MAXRESERVATION ) {}

End Sub

.....

what mean of {} in above case?

thx
Hei

Nov 20 '05 #2
"Hei" <ch******@msn.com> schrieb
Hi All

in the book of example :

Public MustInherit Class Broker

Private const m_MAXRESERVATION As Integer =10
Protected m_reservations() as Reservation

Public Sub New()
m_reservations = New Reservation(m_MAXRESERVATION ) {}

End Sub

.....

what mean of {} in above case?


As it's already been answered in the other thread: It specifies the content
of the array. If there is nothing between the curly braces, the array has 0
items.
--
Armin

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

Nov 20 '05 #3
* "Hei" <ch******@msn.com> scripsit:
in the book of example :

Public MustInherit Class Broker

Private const m_MAXRESERVATION As Integer =10
Protected m_reservations() as Reservation

Public Sub New()
m_reservations = New Reservation(m_MAXRESERVATION ) {}

End Sub

.....

what mean of {} in above case?


A new array if 'Reservation' with 'm_MAXRESERVATION' + 1 elements is
created.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #4
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schrieb
* "Hei" <ch******@msn.com> scripsit:
in the book of example :

Public MustInherit Class Broker

Private const m_MAXRESERVATION As Integer =10
Protected m_reservations() as Reservation

Public Sub New()
m_reservations = New Reservation(m_MAXRESERVATION ) {}

End Sub

.....

what mean of {} in above case?


A new array if 'Reservation' with 'm_MAXRESERVATION' + 1 elements
is created.

I didn't know this syntax! I thought you can _not_ create an array using
"New" unless you fill it by the values in curly braces. After reading your
post, I read the question again and thought the code can not work at all.
The syntax above is very confusing: Does it assign an array containing zero
items because there are no items between the braces, or does it create an
array containing m_MAXRESERVATION items? Contradictive IMO.
--
Armin

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

Nov 20 '05 #5
* "Armin Zingler" <az*******@freenet.de> scripsit:
Private const m_MAXRESERVATION As Integer =10
Protected m_reservations() as Reservation

Public Sub New()
m_reservations = New Reservation(m_MAXRESERVATION ) {}

End Sub

.....

what mean of {} in above case?


A new array if 'Reservation' with 'm_MAXRESERVATION' + 1 elements
is created.


I didn't know this syntax! I thought you can _not_ create an array using
"New" unless you fill it by the values in curly braces. After reading your
post, I read the question again and thought the code can not work at all.
The syntax above is very confusing: Does it assign an array containing zero
items because there are no items between the braces, or does it create an
array containing m_MAXRESERVATION items? Contradictive IMO.


It will work. I have tested it with this code:

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

The code will create an array of 'Form' with 11 elements pointing to
'Nothing'.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #6
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schrieb
I didn't know this syntax! I thought you can _not_ create an array
using "New" unless you fill it by the values in curly braces. After
reading your post, I read the question again and thought the code
can not work at all. The syntax above is very confusing: Does it
assign an array containing zero items because there are no items
between the braces, or does it create an array containing
m_MAXRESERVATION items? Contradictive IMO.


It will work. I have tested it with this code:

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

The code will create an array of 'Form' with 11 elements pointing
to 'Nothing'.


Well, I did understand it and I know what it does, but I tried to say that
the syntax is ambiguous. I could also expect it must create an _empty_ array
because there are no items between the braces.

--
Armin

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

Nov 20 '05 #7
Cor
Hi Armin and Herfried,

I think we should not support this kind of code in the newsgroup.
\\\
Dim x() As Form = New Form(10) {}
///


It give no information to the ones who need it, brings someone only on the
wrong route., when he/she would read this.

Just an opinion.
Cor
Nov 20 '05 #8
* "Cor" <no*@non.com> scripsit:
I think we should not support this kind of code in the newsgroup.
\\\
Dim x() As Form = New Form(10) {}
///


It give no information to the ones who need it, brings someone only on the
wrong route., when he/she would read this.


IMO there is no ambiguity...

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #9
Armin,
I agree its confusing. However
Dim x() As Form = New Form(10) {}
The 10 is giving the number of elements (off by one rule) instead of the 10
being a parameter to the constructor.

Hope this helps
Jay

"Armin Zingler" <az*******@freenet.de> wrote in message
news:OL*************@TK2MSFTNGP11.phx.gbl...
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schrieb I didn't know this syntax! I thought you can _not_ create an array
using "New" unless you fill it by the values in curly braces. After
reading your post, I read the question again and thought the code
can not work at all. The syntax above is very confusing: Does it
assign an array containing zero items because there are no items
between the braces, or does it create an array containing
m_MAXRESERVATION items? Contradictive IMO.
It will work. I have tested it with this code:

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

The code will create an array of 'Form' with 11 elements pointing
to 'Nothing'.


Well, I did understand it and I know what it does, but I tried to say that
the syntax is ambiguous. I could also expect it must create an _empty_

array because there are no items between the braces.

--
Armin

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

Nov 20 '05 #10
Cor,
It is valid VB.NET! Confusing yes, but valid.

Why would we not recommend using it & supporting it?

How would it be any different if I insisted you cannot under any
circumstance use any of the functions in Microsoft.VisualBasic namespace.
Period! Although I largely prefer to use the 'native .NET methods', I will
not say you cannot use Microsoft.VisualBasic.Strings.Mid over
System.String.SubString, instead I will caution people that the arguments to
Mid are base one, where as the arguments to SubString are base zero.

I feel its better to cover "all" the options so others have a choice on
which syntax they want to use...

Just a thought
Jay
"Cor" <no*@non.com> wrote in message
news:e9**************@TK2MSFTNGP12.phx.gbl...
Hi Armin and Herfried,

I think we should not support this kind of code in the newsgroup.
\\\
Dim x() As Form = New Form(10) {}
///


It give no information to the ones who need it, brings someone only on the
wrong route., when he/she would read this.

Just an opinion.
Cor

Nov 20 '05 #11
"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> schrieb
Armin,
I agree its confusing. However
Dim x() As Form = New Form(10) {}


The 10 is giving the number of elements (off by one rule) instead of
the 10 being a parameter to the constructor.


Right, that's why I thought the syntax it is _not_ possible.
Dim f As Form()

f = new form(10) 'error
f = new form(10) {} 'no error

As the second creates a Form array and assigns 0 items, I expect the first
one to create a Form array without assigning an item. So, both are equal.

In other words, I do know that the first creates a new Form and passes 10 to
the constructor, but as it is true, the second should not work because the
curly braces don't make sense when creating a single instance.
--
Armin

http://www.plig.net/nnq/nquote.html
http://www.netmeister.org/news/learn2quote.html
Nov 20 '05 #12
Cor
Hi Jay,

If I am wrong tell it me, from the example from Herfried I understand that
this is the same

Dim myform() As form = New form(10) {}
Dim myform(10) As form

For what you wrote, I tell it always exact in the way you did write it.
Using the Visualbasic functions, describes the things often better than the
..Net methods.
(I try to avoid them but that is my own decission).

If my example above is right, than is this a way of creating a bad readable
program.

Some people like that, but I think those don't have to use VB but C# and
than a lot of documentation with it.

Just a thought

Cor
Nov 20 '05 #13
Armin,
the constructor, but as it is true, the second should not work because the
curly braces don't make sense when creating a single instance. Think of the second as saying "New Array of Form with bounds of 10", only
backwards & mixed up. ;-)
f = new form(10) {} 'no error
The "{}" is the "array of" part & the "(10)" is "with bounds of 10", The
"{}" as "array of" is what caught the OP off guard.

The syntax is documented at:

http://msdn.microsoft.com/library/de...ringArrays.asp

Under the "Initializing Arrays" section.

<quote>
- Assign an array object to the variable, using the New clause. When you
use a New clause, you must follow it with braces ({}), even if they are
empty.

Dim BA(2) As Byte ' Currently contains Nothing (no object).
Dim BA(2) As Byte = New Byte() ' INVALID (New after length specified).
Dim BA() As Byte = New Byte() {} ' Empty Byte array object.
Dim BA() As Byte = New Byte() ' INVALID (missing braces).
Dim BA() As Byte = New Byte(2) ' INVALID (missing braces).
Dim BA() As Byte = New Byte() {0,1,2} ' (0) through (2).
Dim BA() As Byte = New Byte(2) {0,1,2} ' (0) through (2).
</quote>

I would have expected one more example in there.

Dim BA() As Byte = New Byte(2) {}

Hope this helps
Jay

"Armin Zingler" <az*******@freenet.de> wrote in message
news:eK**************@TK2MSFTNGP09.phx.gbl... "Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> schrieb
Armin,
I agree its confusing. However
> Dim x() As Form = New Form(10) {}
The 10 is giving the number of elements (off by one rule) instead of
the 10 being a parameter to the constructor.


Right, that's why I thought the syntax it is _not_ possible.
Dim f As Form()

f = new form(10) 'error
f = new form(10) {} 'no error

As the second creates a Form array and assigns 0 items, I expect the first
one to create a Form array without assigning an item. So, both are equal.

In other words, I do know that the first creates a new Form and passes 10

to the constructor, but as it is true, the second should not work because the
curly braces don't make sense when creating a single instance.
--
Armin

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


Nov 20 '05 #14
Cor,
Dim myform() As form = New form(10) {}
Dim myform(10) As form Yes these two are the same as are these two:

myform() = New form(10) {}
ReDim myform(10)
For what you wrote, I tell it always exact in the way you did write it.
Using the Visualbasic functions, describes the things often better than the .Net methods.
(I try to avoid them but that is my own decission). O.K. maybe the Visual Basic functions were not the best example. Would
Overloading a method verses using Optional parameters have been a better
example? Or using "While - End While" instead of "Do While - Loop"? I am
trying to demostrate that there are a number of alternative ways to do the
exact same thing, sometimes the syntax on the alternative may catch us off
guard, but it is still valid VB.NET.

Also it may be "bad" today, but after looking at the new syntax & using it,
tomorrow it may be "good". ;-)
If my example above is right, than is this a way of creating a bad readable program. I don't like the terms bad & better, as its a matter of perspective (is the
glass half empty or half full). At the same time I am not disagreeing with
you one maybe "bad" and the other may be "better", as I find the Visual
Basic functions make things easier.

However for beginner developers I will agree it can be confusing. Which is
where I prefer to point out it is valid, try to explain how it works.

Hope this helps
Jay

"Cor" <no*@non.com> wrote in message
news:u8**************@TK2MSFTNGP11.phx.gbl... Hi Jay,

If I am wrong tell it me, from the example from Herfried I understand that
this is the same

Dim myform() As form = New form(10) {}
Dim myform(10) As form

For what you wrote, I tell it always exact in the way you did write it.
Using the Visualbasic functions, describes the things often better than the .Net methods.
(I try to avoid them but that is my own decission).

If my example above is right, than is this a way of creating a bad readable program.

Some people like that, but I think those don't have to use VB but C# and
than a lot of documentation with it.

Just a thought

Cor

Nov 20 '05 #15
"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> schrieb
Armin,
the constructor, but as it is true, the second should not work
because the curly braces don't make sense when creating a single
instance. Think of the second as saying "New Array of Form with bounds of 10",
only backwards & mixed up. ;-)


:-)
f = new form(10) {} 'no error


The "{}" is the "array of" part & the "(10)" is "with bounds of 10",
The "{}" as "array of" is what caught the OP off guard.

The syntax is documented at:

http://msdn.microsoft.com/library/de...ringArrays.asp
Under the "Initializing Arrays" section.

<quote>
- Assign an array object to the variable, using the New clause. When
you use a New clause, you must follow it with braces ({}), even if
they are empty.

Dim BA(2) As Byte ' Currently contains Nothing (no object).
Dim BA(2) As Byte = New Byte() ' INVALID (New after length
specified). Dim BA() As Byte = New Byte() {} ' Empty Byte array
object.
Dim BA() As Byte = New Byte() ' INVALID (missing braces).
Dim BA() As Byte = New Byte(2) ' INVALID (missing braces).
Dim BA() As Byte = New Byte() {0,1,2} ' (0) through (2).
Dim BA() As Byte = New Byte(2) {0,1,2} ' (0) through (2).
</quote>

Yes, it's documented, but I'd see it this way:
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
Do you see why I'm confused?

I would have expected one more example in there.

Dim BA() As Byte = New Byte(2) {}


The missing example shows that they forgot to disallow this version. ;-)
--
Armin

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

Nov 20 '05 #16
* "Cor" <no*@non.com> scripsit:
If I am wrong tell it me, from the example from Herfried I understand that
this is the same

Dim myform() As form = New form(10) {}
Dim myform(10) As form
Yes, they are the same. But you will need the fist one when reassigning
an array of 'form' later in the code, not in the declaration directly.
For what you wrote, I tell it always exact in the way you did write it.
Using the Visualbasic functions, describes the things often better than the
.Net methods.
(I try to avoid them but that is my own decission).
The "new" way of declaring arrays is IMO not the best one:

\\\
Dim afrm As MyForm()
///

*really ugly*
If my example above is right, than is this a way of creating a bad readable
program.


This depends on the skills of the reader.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #17
* "Armin Zingler" <az*******@freenet.de> scripsit:
I agree its confusing. However
Dim x() As Form = New Form(10) {}
The 10 is giving the number of elements (off by one rule) instead of
the 10 being a parameter to the constructor.


Right, that's why I thought the syntax it is _not_ possible.
Dim f As Form()

f = new form(10) 'error


Only error if there is not a parameterized ctor defined in 'form'.
f = new form(10) {} 'no error

As the second creates a Form array and assigns 0 items, I expect the first
one to create a Form array without assigning an item. So, both are equal.
The curly braces are only used to aviod ambiguity (ctor call vs. array
declaration).
In other words, I do know that the first creates a new Form and passes 10 to
the constructor, but as it is true, the second should not work because the
curly braces don't make sense when creating a single instance.


Why not? Where do you create a "single instance"?

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #18
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schrieb
* "Armin Zingler" <az*******@freenet.de> scripsit:
I agree its confusing. However

> Dim x() As Form = New Form(10) {}

The 10 is giving the number of elements (off by one rule) instead
of the 10 being a parameter to the constructor.


Right, that's why I thought the syntax it is _not_ possible.
Dim f As Form()

f = new form(10) 'error


Only error if there is not a parameterized ctor defined in 'form'.


No, also error if a parameterized ctor is definied because f is declared as
an array.
f = new form(10) {} 'no error

As the second creates a Form array and assigns 0 items, I expect
the first one to create a Form array without assigning an item. So,
both are equal.


The curly braces are only used to aviod ambiguity (ctor call vs.
array declaration).
In other words, I do know that the first creates a new Form and
passes 10 to the constructor, but as it is true, the second should
not work because the curly braces don't make sense when creating a
single instance.


Why not? Where do you create a "single instance"?


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
--
Armin

Nov 20 '05 #19
Armin,
Do you see why I'm confused?
I knew why you confused from the start, as I was a little startled/taken
back when I first saw the syntax, then it was: O.K. I can do that.
I would have expected one more example in there.

Dim BA() As Byte = New Byte(2) {}


The missing example shows that they forgot to disallow this version. ;-)


<rant>I have a bigger problem with the "off by one" syntax in VB.NET arrays.
In that VB.NET arrays use upper bound as oppose to number of elements. To me
that is just asking for trouble as I suspect most beginners expect the low
bound to be one, not zero. Which means they have this 'hidden' element
floating around.

For example:

<beginner mode>
Dim list(2) As String ' define a two element array
list(1) = "Hello"
list(2) = "World"
Dim str As String
str = String.Join(" ", list)

Why does my str have a leading space on it?

</beginner mode>
</rant>

Just a thought,
Jay

"Armin Zingler" <az*******@freenet.de> wrote in message
news:OX**************@TK2MSFTNGP09.phx.gbl... "Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> schrieb
Armin,
the constructor, but as it is true, the second should not work
because the curly braces don't make sense when creating a single
instance.

Think of the second as saying "New Array of Form with bounds of 10",
only backwards & mixed up. ;-)


:-)
f = new form(10) {} 'no error


The "{}" is the "array of" part & the "(10)" is "with bounds of 10",
The "{}" as "array of" is what caught the OP off guard.

The syntax is documented at:

http://msdn.microsoft.com/library/de...ringArrays.asp

Under the "Initializing Arrays" section.

<quote>
- Assign an array object to the variable, using the New clause. When
you use a New clause, you must follow it with braces ({}), even if
they are empty.

Dim BA(2) As Byte ' Currently contains Nothing (no object).
Dim BA(2) As Byte = New Byte() ' INVALID (New after length
specified). Dim BA() As Byte = New Byte() {} ' Empty Byte array
object.
Dim BA() As Byte = New Byte() ' INVALID (missing braces).
Dim BA() As Byte = New Byte(2) ' INVALID (missing braces).
Dim BA() As Byte = New Byte() {0,1,2} ' (0) through (2).
Dim BA() As Byte = New Byte(2) {0,1,2} ' (0) through (2).
</quote>

Yes, it's documented, but I'd see it this way:
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
Do you see why I'm confused?

I would have expected one more example in there.

Dim BA() As Byte = New Byte(2) {}


The missing example shows that they forgot to disallow this version. ;-)
--
Armin

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

Nov 20 '05 #20
* "Armin Zingler" <az*******@freenet.de> scripsit:
I agree its confusing. However

>> Dim x() As Form = New Form(10) {}

The 10 is giving the number of elements (off by one rule) instead
of the 10 being a parameter to the constructor.

Right, that's why I thought the syntax it is _not_ possible.
Dim f As Form()

f = new form(10) 'error


Only error if there is not a parameterized ctor defined in 'form'.


No, also error if a parameterized ctor is definied because f is declared as
an array.


Sorry, I missed that...
f = new form(10) {} 'no error

As the second creates a Form array and assigns 0 items, I expect
the first one to create a Form array without assigning an item. So,
both are equal.


The curly braces are only used to aviod ambiguity (ctor call vs.
array declaration).
In other words, I do know that the first creates a new Form and
passes 10 to the constructor, but as it is true, the second should
not work because the curly braces don't make sense when creating a
single instance.


Why not? Where do you create a "single instance"?


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


In the last line: Why should it call the ctor? The code below will
cause a compile time error because an array cannot be assigned to a
non-array variable:

\\\
Dim f As X
f = New X(10) {}
..
..
..
Public Class X
Public Sub New(ByVal i As Integer)
...
End Sub
End Class
///

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #21
Cor
Hi Jay,
Which is where I prefer to point out it is valid, try to explain how it

works.

That was the text I was starting with, stuffed it, and then left it out, do
not know why.

The rest we also agree.

Cor
Nov 20 '05 #22
Cor
Herfried,
If my example above is right, than is this a way of creating a bad readable program.


This depends on the skills of the reader.

When you write a program, afterwards it is hard enought for a reader with a
lot of skills to understand it, specialy when it is a program from 10 years
old with an unused language, so if it does not hurt your program, try to
make it readable for the one with few skills.

Just a thought from someone who has bad expierences with this from others.
(And I am not the only one)

Cor
Nov 20 '05 #23
* "Cor" <no*@non.com> scripsit:
If my example above is right, than is this a way of creating a bad
readable
program.
This depends on the skills of the reader.

When you write a program, afterwards it is hard enought for a reader with a
lot of skills to understand it, specialy when it is a program from 10 years
old with an unused language, so if it does not hurt your program, try to
make it readable for the one with few skills.


Then we should avoid using arrays, loops, recursion, ...

SCNR
Just a thought from someone who has bad expierences with this from others.
(And I am not the only one)


Just a thought too.

--
Herfried K. Wagner [MVP]
<http://www.mvps.org/dotnet>
Nov 20 '05 #24
Armin, Cor, Herfried & others,
<rant>I have a bigger problem with the "off by one" syntax in VB.NET arrays.

I'll be much happier with the new System.Collections.Generic.List(Of T)
class in Whidbey, then the sometimes strange syntax of VB.NET arrays or the
boxing effect of an ArrayList.

http://longhorn.msdn.microsoft.com/l...list/list.aspx

The List(Of T) class effectively combines the type safety of an Array with
the flexibility of an ArrayList. Which means we can have an List(Of Integer)
and get the speed & efficiency of an array of Integer, yet we can still call
List(Of Integer).Add(Integer) to expand the collection by adding an integer
on the end!

If you happen to have Whidbey I would suggest you check out the generic
collections! in the System.Collections.Generic namespace.

Note: the (Of T) syntax is a type parameter, it indicates the actual type
that the List holds, so when I say List(Of Integer) I have a list of
integers, while with List(Of String) I have a list of strings. Yep something
new and different, but this is very good!

Jay

"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> wrote in message
news:O0**************@TK2MSFTNGP12.phx.gbl... Armin,
Do you see why I'm confused?
I knew why you confused from the start, as I was a little startled/taken
back when I first saw the syntax, then it was: O.K. I can do that.
I would have expected one more example in there.

Dim BA() As Byte = New Byte(2) {}


The missing example shows that they forgot to disallow this version. ;-)


<rant>I have a bigger problem with the "off by one" syntax in VB.NET

arrays. In that VB.NET arrays use upper bound as oppose to number of elements. To me that is just asking for trouble as I suspect most beginners expect the low
bound to be one, not zero. Which means they have this 'hidden' element
floating around.

For example:

<beginner mode>
Dim list(2) As String ' define a two element array
list(1) = "Hello"
list(2) = "World"
Dim str As String
str = String.Join(" ", list)

Why does my str have a leading space on it?

</beginner mode>
</rant>

Just a thought,
Jay

"Armin Zingler" <az*******@freenet.de> wrote in message
news:OX**************@TK2MSFTNGP09.phx.gbl...
"Jay B. Harlow [MVP - Outlook]" <Ja********@email.msn.com> schrieb
Armin,
> the constructor, but as it is true, the second should not work
> because the curly braces don't make sense when creating a single
> instance.
Think of the second as saying "New Array of Form with bounds of 10",
only backwards & mixed up. ;-)


:-)
> f = new form(10) {} 'no error

The "{}" is the "array of" part & the "(10)" is "with bounds of 10",
The "{}" as "array of" is what caught the OP off guard.

The syntax is documented at:

http://msdn.microsoft.com/library/de...ringArrays.asp

Under the "Initializing Arrays" section.

<quote>
- Assign an array object to the variable, using the New clause. When
you use a New clause, you must follow it with braces ({}), even if
they are empty.

Dim BA(2) As Byte ' Currently contains Nothing (no object).
Dim BA(2) As Byte = New Byte() ' INVALID (New after length
specified). Dim BA() As Byte = New Byte() {} ' Empty Byte array
object.
Dim BA() As Byte = New Byte() ' INVALID (missing braces).
Dim BA() As Byte = New Byte(2) ' INVALID (missing braces).
Dim BA() As Byte = New Byte() {0,1,2} ' (0) through (2).
Dim BA() As Byte = New Byte(2) {0,1,2} ' (0) through (2).
</quote>

Yes, it's documented, but I'd see it this way:
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
Do you see why I'm confused?

I would have expected one more example in there.

Dim BA() As Byte = New Byte(2) {}


The missing example shows that they forgot to disallow this version. ;-)
--
Armin

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


Nov 20 '05 #25
"Herfried K. Wagner [MVP]" <hi***************@gmx.at> schrieb

In other words, I do know that the first creates a new Form
and passes 10 to the constructor, but as it is true, the second
should not work because the curly braces don't make sense when
creating a single instance.

Why not? Where do you create a "single instance"?
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


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


For the same reason as in the 2nd line.
The code below will
cause a compile time error because an array cannot be assigned to a
non-array variable:

\\\
Dim f As X
f = New X(10) {}
.
.
.
Public Class X
Public Sub New(ByVal i As Integer)
...
End Sub
End Class
///

--
Armin

Nov 20 '05 #26
Cor

Then we should avoid using arrays, loops, recursion, ...

I am glad you start to understand it, especialy endless ones.

:-)))))))))))))))))))))))))))))

This was my EOT.

Nov 20 '05 #27
On 18 Nov 2003 18:40:36 +0100, Herfried K. Wagner [MVP] wrote:

The "new" way of declaring arrays is IMO not the best one:

\\\
Dim afrm As MyForm()
///

*really ugly*


I agree with you Herfried. The parentheses should be on the array variable
like this:

Dim afrm() As MyForm

That is more intuitive to me.

--
Chris

To send me an E-mail, remove the underscores and lunchmeat from my E-Mail
address.
Nov 20 '05 #28

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: Phil Powell | last post by:
I am having this problem: My PHP script will set a cookie, it's there in my /Cookies folder. I delete the cookie (I have to for testing purposes, the PHP script I run behaves according to this...
5
by: Bruce | last post by:
I have a number of forms that do significant work based on variables POSTed from the form. What is the common method of detecting and preventing this work from being done when the form is POSTed as...
1
by: Jiten | last post by:
Hi Cor I spoke with u previously about this problem i had and u gave me some code that helped me. That code worked fine but i have now encountered another issuee that im hoping u may know how to...
8
by: jon morgan | last post by:
OK, I'm going to be brave. There is a bug in VS.Net 1.1 that causes random compiler errors. I have raised this issue in posts at least three time in the past couple of months without attracting...
17
by: Gabriel Mejía | last post by:
Services or applications using ActiveX Data Objects (ADO) 2.0 or greater may intermittently return empty recordsets on queries that should be returning valid results. At the time the problem...
3
by: penny336 | last post by:
dear all, i am using vc++ 6.0 sp5 i have a class called Address,it allocated some memory space for streetname and city i first define it as Address add = new Address("Madrian","UK"); ......
11
by: Steven T. Hatton | last post by:
In the past there have been lengthy discussiions regarding the role of header files in C++. People have been very adamat about header files serving as in interface to the implementation. I do...
6
by: teedilo | last post by:
We have an application with a SQL Server 2000 back end that is fairly database intensive -- lots of fairly frequent queries, inserts, updates -- the gamut. The application does not make use of...
34
by: Reinhold Birkenfeld | last post by:
Hi, the arguments in the previous thread were convincing enough, so I made the Path class inherit from str/unicode again. It still can be found in CVS:...
5
by: Mike TI | last post by:
March 24, 2006 Hi all I am new to VB.NET and am using VB.NET 2005. I have an MDI form with a Split Container Control. On demand I am adding and removing User Controls on Panel 2. I am using...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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: 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?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.