I tried using arrays... but it fails, saying that im using an
Unassigned Variable:
its like:
string[] strString;
int x=1;
for(.......){
strString[x] = ....... ;
}
It says strString is unassigned, if I remove the [x] it says "missing
identifier"...
But if the array worked, it would be perfect.
Thx.
> Would an arraylist work for you?
Mantorok - 21 Jun 2007 15:15 GMT
> I tried using arrays... but it fails, saying that im using an
> Unassigned Variable:
[quoted text clipped - 11 lines]
>
> But if the array worked, it would be perfect.
You need an ArrayList as it's dynamic, with an ArrayList you can add as many
items as you want (an array is of fixed length). Use the Add method to add
a new entry into the AL and you will end up with a complete list of field
entries.
HTH
Kev
Mark Rae - 21 Jun 2007 15:21 GMT
> I tried using arrays... but it fails, saying that im using an
> Unassigned Variable:
[quoted text clipped - 11 lines]
>
> But if the array worked, it would be perfect.
Sounds like all you need is a generic e.g.
List<string> MyList = new List<string>();
MyList.Add("One");
MyList.Add("Two");
MyList.Add("Three");
etc
Or if you need keys and values, consider a Dictionary<string, string>
generic...

Signature
http://www.markrae.net
Doogie - 21 Jun 2007 15:31 GMT
> I tried using arrays... but it fails, saying that im using an
> Unassigned Variable:
[quoted text clipped - 12 lines]
>
> But if the array worked, it would be perfect.
Some of the others have mentioned this, but I meant ArrayList, not an
array. Also, depending on what version of .NET you are in, you could
use generics as discussed below too - although I'm new into that
version of .NET and don't know a lot about them.
Jl_G_0 - 21 Jun 2007 15:52 GMT
you guys really helped me here... Im using the arraylist, its simple
and the code is almost done.
thx again.
Laurent Bugnion, MVP - 21 Jun 2007 16:48 GMT
Hi,
> you guys really helped me here... Im using the arraylist, its simple
> and the code is almost done.
>
> thx again.
Using List<> instead of ArrayList is usually a good idea, unless you
have to code against .NET 1.1. ArrayList contains Objects only, so you
need to cast to the desired type (in that case, string) every time.
List<> is a generic collection, so you don't need to cast the elements.
List<string> myList = new List<string>();
myList.Add(...);
HTH,
Laurent

Signature
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft.ch
PhotoAlbum: http://www.galasoft.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
sloan - 21 Jun 2007 17:12 GMT
A (2.0) Dictionary < string , MyClass >
or
Dictionary < int , MyClass >
are options as well.
> Hi,
>
[quoted text clipped - 13 lines]
> HTH,
> Laurent
Laurent Bugnion, MVP - 21 Jun 2007 18:26 GMT
Hi,
> A (2.0) Dictionary < string , MyClass >
> or
> Dictionary < int , MyClass >
> are options as well.
The OP wants a dynamic array of Strings. I don't see the need to use a
Dictionary for this, to be honest. Dictionaries as well as Hashtables
have a hit on performances, compared to non-keyed collections.
HTH,
Laurent

Signature
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft.ch
PhotoAlbum: http://www.galasoft.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch