Solved

Arrays C#

Posted on 2006-11-29
4
924 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

This is an explanation of a simple data model to help parse a JSON feed
Displaying an arrayList in a listView using the default adapter is rarely the best solution. To get full control of your display data, and to be able to refresh it after editing, requires the use of a custom adapter.
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…

734 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