Solved

Arrays C#

Posted on 2006-11-29
4
921 Views
Last Modified: 2012-06-27
If i want to fill an array with numbers, but im not sure what the size is until i run the program how do i make an array adjustable?  I assume you would need to put it in some kind of for loop,
0
Comment
Question by:jmkotman
  • 2
4 Comments
 
LVL 4

Expert Comment

by:Raymun
ID: 18043111
Use a vector
0
 
LVL 4

Expert Comment

by:Raymun
ID: 18043128
or arraylist
0
 

Author Comment

by:jmkotman
ID: 18043155
If i read in a list of numbers i would usually do this

static int[] array = new int[10];

for(int i=0; i<split.Length; i++)
{
       array[i] = int.Parse(split[i]);
}

ok so thats going to put them in the array.  Now when i go to sort that array using a bubble sort if the numbers which were read in didn't fill the whole array i get "0" when i sort it and it messes the sort up.
0
 
LVL 18

Accepted Solution

by:
Ravi Singh earned 500 total points
ID: 18044437
Hi, as Raymun suggested, you can use a dynamic collection such as an ArrayList:

ArrayList array = new ArrayList();

for (int i = 0; i < split.length; i++)
      array.Add(split[i]);

//looping through the ArrayList
int currentInt;
for (int j = 0; j < array.Count; j++)
     currentInt = int.Parse(array[j].ToString());
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
topping1 challenge 7 72
Modify a small python script 19 96
Basic Java Case or If-Else statement... 3 43
Plain Text Editor for iPad 6 57
This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
A short article about problems I had with the new location API and permissions in Marshmallow
An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now