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

Dim lbl( ) As Label = New Label( ){...} vs Dim lbl( ) As Label = {...}

P: n/a
Ron
Hello,

I created an array of label controls like this:

Dim lbl() As Label = {Me.lbl1, Me.lbl2, Me.lbl3}

and was able to iterate through the array. But then I saw
another way to declare the same array:

Dim lbl() As Label = New Label(){Me.lbl1, Me.lbl2, Me.lbl3}

Both ways seems to work fine, but I want to get in the
practice of doing this correctly. Is there a difference
between using New or not for this? If so, what is the
difference?

Thanks,
Ron
Nov 21 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Ron" <an*******@discussions.microsoft.com> schrieb:
I created an array of label controls like this:

Dim lbl() As Label = {Me.lbl1, Me.lbl2, Me.lbl3}

and was able to iterate through the array. But then I saw
another way to declare the same array:

Dim lbl() As Label = New Label(){Me.lbl1, Me.lbl2, Me.lbl3}

Both ways seems to work fine, but I want to get in the
practice of doing this correctly. Is there a difference
between using New or not for this? If so, what is the
difference?


There is no difference. I would prefer the first solution because of the
higher readability.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #2

P: n/a
"Ron" <an*******@discussions.microsoft.com> schrieb:
I created an array of label controls like this:

Dim lbl() As Label = {Me.lbl1, Me.lbl2, Me.lbl3}

and was able to iterate through the array. But then I saw
another way to declare the same array:

Dim lbl() As Label = New Label(){Me.lbl1, Me.lbl2, Me.lbl3}

Both ways seems to work fine, but I want to get in the
practice of doing this correctly. Is there a difference
between using New or not for this? If so, what is the
difference?


There is no difference. I would prefer the first solution because of the
higher readability.

--
Herfried K. Wagner [MVP]
<URL:http://dotnet.mvps.org/>

Nov 21 '05 #3

P: n/a
Ron,
As Herfried suggests I normally use the first syntax, however you need the
second syntax when you want an array, but you don't want or need the
variable.

For example:

Sub Test(labels() As Label)
End Sub

Test(New Label(){Me.lbl1, Me.lbl2, Me.lbl3})

Here I want to send an array of Labels to the Test method, however I don't
want or need an array variable to hold them.

Hope this helps
Jay

"Ron" <an*******@discussions.microsoft.com> wrote in message
news:63****************************@phx.gbl...
Hello,

I created an array of label controls like this:

Dim lbl() As Label = {Me.lbl1, Me.lbl2, Me.lbl3}

and was able to iterate through the array. But then I saw
another way to declare the same array:

Dim lbl() As Label = New Label(){Me.lbl1, Me.lbl2, Me.lbl3}

Both ways seems to work fine, but I want to get in the
practice of doing this correctly. Is there a difference
between using New or not for this? If so, what is the
difference?

Thanks,
Ron

Nov 21 '05 #4

P: n/a
Ron,
As Herfried suggests I normally use the first syntax, however you need the
second syntax when you want an array, but you don't want or need the
variable.

For example:

Sub Test(labels() As Label)
End Sub

Test(New Label(){Me.lbl1, Me.lbl2, Me.lbl3})

Here I want to send an array of Labels to the Test method, however I don't
want or need an array variable to hold them.

Hope this helps
Jay

"Ron" <an*******@discussions.microsoft.com> wrote in message
news:63****************************@phx.gbl...
Hello,

I created an array of label controls like this:

Dim lbl() As Label = {Me.lbl1, Me.lbl2, Me.lbl3}

and was able to iterate through the array. But then I saw
another way to declare the same array:

Dim lbl() As Label = New Label(){Me.lbl1, Me.lbl2, Me.lbl3}

Both ways seems to work fine, but I want to get in the
practice of doing this correctly. Is there a difference
between using New or not for this? If so, what is the
difference?

Thanks,
Ron

Nov 21 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.