|
-
March 23rd, 2009, 11:55 PM
#1
String array
Code:
string[] str_a = new string[]; // COMPLIER DOES NOT LIKE THIS
string[] str_a = new string[256]; // COMPLIER wants THIS
int col=0;
while ( BLAA BLAA BLAA))
{
str_a[col++] = get(...);
}
return str_a; // but the size is of the array is 256 not value of col
I DONT WANT TO SET MY STRING [] TO HAVE 256.
one WAY I READ WAS TO USE LIST<LIST<string>> but i still try not to do that.
Final question is this :
can teh size of the array be altered from 256 to what the value of COL is somehow before being returned back?
-
March 24th, 2009, 12:12 AM
#2
Re: String array
Why all of the alternated CAPS?
Like you read, use a generic list. It is made to be used as a dynamically sized array, so use it:
Code:
List<string> strings = new List<string>();
strings.Add("one");
strings.Add("two");
strings.Add("three");
And if you need o work with it as an array at some point, there is always the ToArray() method.
-
March 24th, 2009, 12:21 AM
#3
Re: String array
Thanks for the reply.
My keyborard is stuffed.sorry about the CAPS.
-
March 24th, 2009, 01:23 AM
#4
Re: String array
Honestly, without knowing the "blah blah blah" part of that loop, it is hard to give you any more advice. You are just looping through an array, but you don't show us how you are obtaining the value of col. At what point does the loop terminate? Can't you just the test value before entering the loop? You could then declare the array after setting 'col'.
-
March 24th, 2009, 04:14 AM
#5
Re: String array
If you don't know the size of array before you allocate it, use List<string> to accomodate the uknown number of items and than call ToArray() on it to get an instance of string[].
- Make it run.
- Make it right.
- Make it fast.
Don't hesitate to rate my post. 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|