Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Arrays C#

Posted on 2006-11-29
4
Medium Priority
?
929 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 2000 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
The SignAloud Glove is capable of translating American Sign Language signs into text and audio.
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 …
Introduction to Processes

610 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