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

Array Size

Do I have to know the exact number of occurences of an array object when I
declared it, or can I add just declare the object and do not have to
declare the length?

For instance...

TableRow[] myTableRows;

Table row1 = new TableRow();
myTableRows[0] = row1;
Table row2 = new TableRow();
myTableRows[1] = row2;

I think I had to know the size of my array - at least in Java I did, so I
guess it is the same with C#?

If I do not know the size exactly, is it best for me to choose a number
that I know it will not exceed (small number like 10) or should I just use
a hashtable to store all of my row in? Or is there a better object ot use?

Nov 18 '05 #1
3 1678
You might be better off with ArrayList, which has Add/AddRange methods

HTH
Alex

"Jim Heavey" <Ji*******@nospam.com> wrote in message
news:Xn*********************************@207.46.24 8.16...
Do I have to know the exact number of occurences of an array object when I
declared it, or can I add just declare the object and do not have to
declare the length?

For instance...

TableRow[] myTableRows;

Table row1 = new TableRow();
myTableRows[0] = row1;
Table row2 = new TableRow();
myTableRows[1] = row2;

I think I had to know the size of my array - at least in Java I did, so I
guess it is the same with C#?

If I do not know the size exactly, is it best for me to choose a number
that I know it will not exceed (small number like 10) or should I just use
a hashtable to store all of my row in? Or is there a better object ot use?

Nov 18 '05 #2
To resize an array you essentially need to create a new array of the
proper size and copy over the elements of the old array.

If you need dynamic add/remove capabilities, you might want to look into
the ArrayList. It does appropriate resizing for you under the covers.

For more info on arrays and ArrayLists, check out:

An Extensive Examination of Data Structures: Part 1
http://msdn.microsoft.com/vcsharp/de...ures_guide.asp

Happy Programming!

--

Scott Mitchell
mi******@4guysfromrolla.com
http://www.4GuysFromRolla.com
http://www.ASPFAQs.com
http://www.ASPMessageboard.com

* When you think ASP, think 4GuysFromRolla.com!
Nov 18 '05 #3
Here's another option. If you don't know exaclt how many items you're going
to end up with, you can start with an arrayList collection and then, when
you're done, turn it into as array if neded.

ArrayList myTableRows=new ArrayList();
Table row1 = new TableRow();
myTableRows.Add(row1);
Table row2 = new TableRow();
myTableRows.Add(row2);
TableRow[] theTableRowArray;
theTableRowArray=myTableRows.ToArray(TableRow);

"Jim Heavey" <Ji*******@nospam.com> wrote in message
news:Xn*********************************@207.46.24 8.16...
Do I have to know the exact number of occurences of an array object when I
declared it, or can I add just declare the object and do not have to
declare the length?

For instance...

TableRow[] myTableRows;

Table row1 = new TableRow();
myTableRows[0] = row1;
Table row2 = new TableRow();
myTableRows[1] = row2;

I think I had to know the size of my array - at least in Java I did, so I
guess it is the same with C#?

If I do not know the size exactly, is it best for me to choose a number
that I know it will not exceed (small number like 10) or should I just use
a hashtable to store all of my row in? Or is there a better object ot use?

Nov 18 '05 #4

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

Similar topics

13
by: Noah Spitzer-Williams | last post by:
Hello guys, I would like to do something seemingly simple: find out if an element in an array that is passed to my function exists. I used to think I could just do: if (arr) ... However, if...
58
by: jr | last post by:
Sorry for this very dumb question, but I've clearly got a long way to go! Can someone please help me pass an array into a function. Here's a starting point. void TheMainFunc() { // Body of...
3
by: ritchie | last post by:
Hi all! Still working on this program! Just to recap, I am writing a program to sort an array with four different sort algorythms. I am having a little trouble at the moment though! Now, I...
6
by: Herrcho | last post by:
in K&R Chapter 6.3 it mentions two methods to calculate NKEYS. and points out the first one which is to terminate the list of initializers with a null pointer, then loop along keytab until the...
28
Nepomuk
by: Nepomuk | last post by:
Hi! I've read, that in C++ there's no predefined method, to calculate the size of an array. However, it's supposed to work withsizeof(array)/sizeof(array)Now, this does work in some situations, but...
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: 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:
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
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,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.