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

array creation (elementary question)

gmb
(.NET 2.0)

code:
array<TextBox^^dialog_txb = {gcnew TextBox(),gcnew TextBox(),gcnew
TextBox(),gcnew TextBox(),gcnew TextBox()};

question:
Is there a shorter way to declare and initialize an array of 5 objects
without repetition of "gcnew TextBox()" ?
(What if I need to create an array with much bigger number of elements?)

Thanks in advance,
gmb

Jun 3 '07 #1
2 1734
You only should use that syntax if you have the specific instances ready to
insert.
Instead use:
array<TextBox^^dialog_txb = gcnew array<TextBox^>(5);

and then when you have the instance of TextBox that you want in the array,
add them using standard array syntax (e.g., dialog_txb[0] =
some_specific_textbox, or dialog_txb[0] = gcnew TextBox() - obviously in a
loop if you have many that you're adding this way).
--
David Anton
www.tangiblesoftwaresolutions.com
Instant C#: VB to C# converter
Instant VB: C# to VB converter
C++ to C# Converter: converts C++ to C#
Instant C++: converts C# or VB to C++/CLI
"gmb" wrote:
(.NET 2.0)

code:
array<TextBox^^dialog_txb = {gcnew TextBox(),gcnew TextBox(),gcnew
TextBox(),gcnew TextBox(),gcnew TextBox()};

question:
Is there a shorter way to declare and initialize an array of 5 objects
without repetition of "gcnew TextBox()" ?
(What if I need to create an array with much bigger number of elements?)

Thanks in advance,
gmb

Jun 3 '07 #2

"gmb" <di*********@wp.plwrote in message
news:u$**************@TK2MSFTNGP04.phx.gbl...
(.NET 2.0)

code:
array<TextBox^^dialog_txb = {gcnew TextBox(),gcnew TextBox(),gcnew
TextBox(),gcnew TextBox(),gcnew TextBox()};

question:
Is there a shorter way to declare and initialize an array of 5 objects
without repetition of "gcnew TextBox()" ?
Please realize that .NET has no concept of initialized array. If you look
at the IL, you will see that it first creates the array, and then _assigns_
(not initializes) each element in sequence. So you will get the exact same
behavior using a loop.
(What if I need to create an array with much bigger number of elements?)

Thanks in advance,
gmb

Jun 4 '07 #3

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

Similar topics

2
by: ip4ram | last post by:
I used to work with C and have a set of libraries which allocate multi-dimensional arrays(2 and 3) with single malloc call. data_type **myarray =...
7
by: Amittai Aviram | last post by:
Hi! Is there a convenient way to create a null-terminated string out of an array of type int? Is there a standard library function I can use? If so, how? This seems elementary, but I can't...
39
by: hpy_awad | last post by:
I know that group is for C not for C++ but please try to help me , How can I declare size of an array as variable value came from screen? #include "iostream.h" #include "iomanip.h" #include...
5
by: Stijn van Dongen | last post by:
A question about void*. I have a hash library where the hash create function accepts functions unsigned (*hash)(const void *a) int (*cmp) (const void *a, const void *b) The insert function...
11
by: Geoff Cox | last post by:
Hello, I am trying to get a grip on where to place the initialization of two arrays in the code below which was created using Visual C++ 2005 Express Beta 2... private: static array<String^>^...
21
by: yeti349 | last post by:
Hi, I'm using the following code to retrieve data from an xml file and populate a javascript array. The data is then displayed in html table form. I would like to then be able to sort by each...
1
by: None | last post by:
Dynamic array creation Hi all... here's a good one for you... I have a situation where I have some bean, and I need to populate an array field in it... here's the problem... I do not know the...
33
by: Zytan | last post by:
I want to make a zero element array. I know that Nothing is not the same as a zero element array, since I can't get the length of, or iterate through, an array = Nothing. I could make a zero...
5
by: David Golightly | last post by:
Quick question for the gurus out there: in ECMAScript, one can create a new Array object with a length like so: var animals = new Array(128); This creates a new Array object with a "length"...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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
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
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
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...

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.