473,395 Members | 2,446 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,395 software developers and data experts.

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

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

Similar topics

3
by: TR | last post by:
Is it possible with CSS to prevent this wrapping alignment with a checkbox with a nested label? This is the label of the checkbox that wraps beneath it I'd prefer it looked like...
3
by: kaiser | last post by:
Hello, Am new to C# and am playing around trying to get a while loop to display a int on a windows console using label. private void btnGo_Click(object sender, System.EventArgs e) { int Counter...
2
by: Shapper | last post by:
Hello, I am creating a contact form in ASP.NET and I need to access the labels on Page_Load on my aspx.vb file. The other elements such as input box and text box don't need to be accessible....
7
by: anthony | last post by:
I know this is probably talk about millions of time here, but I cant seem to find a close one, I am so used to the vb6 control array, now that I have to use vb.net for my project, I like to do...
4
by: Phil | last post by:
Hi, How to add programmatically a label into a content page? I tried this but doesn't work: Thanks Phil content page:
0
by: anniejacob | last post by:
hi, i want to drag n drop a label from 1 panel to other , when it is dragged to the other panel i want it 2 create another label there in panel2. i hav written the below code . public partial...
0
by: CSharpner | last post by:
How can I do the following?: Have a label on a form have its Text property bound to a setting from one of my DLL library's config files? I've followed these instructions to successfully get...
2
by: THEAF | last post by:
hi, i'm tryin to create this math questions form for my sister. the form has 2 labels where random numbers show, a text box where the answer is entered, a next button the next numbers and an exit...
1
by: karthik25 | last post by:
Hi, The following code creates a tab container, 5 tab panels, buttons, labels. I was able to add event handlers to the button. But how am i supposed to access the dynamically created labels? For...
1
by: jagdeep gupta | last post by:
Thanks a lot friend but a problem does occur is i have added a br tag as well but it is not shown in output plz check: TextBox textBoxArr; Label lbl=new Label; Label lblbr=new Label(); ...
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
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
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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.