Solved

Arrays C#

Posted on 2006-11-29
4
920 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
Comment Utility
Use a vector
0
 
LVL 4

Expert Comment

by:Raymun
Comment Utility
or arraylist
0
 

Author Comment

by:jmkotman
Comment Utility
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
Comment Utility
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

Iteration: Iteration is repetition of a process. A student who goes to school repeats the process of going to school everyday until graduation. We go to grocery store at least once or twice a month to buy products. We repeat this process every mont…
This article will show, step by step, how to integrate R code into a R Sweave document
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

772 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

14 Experts available now in Live!

Get 1:1 Help Now