When using the .ToArray()
function is it necessary to implicitly define the size of the array in order to hold of the characters that were in the list you're converting?
String [] array = List.ToArray();
I tried doing this because I needed to use the .GetValue()
ability of the array, however, the array is maintaining a size of 1 and not holding the material from the list. Am I trying to use the .ToArray()
incorrectly?
colAndDelimiter = new List<string>();
colAndDelimiter.Add(text);
String [] cd = colAndDelimiter.ToArray();
This is all of the code I have that effects the array. When I Console.WriteLine()
the list it gives me the entirety of the text. I may be confused about how list works. Is it storing everything as a single item, and that's why the array only shows one place?
You don't need to convert it to an array to get specific characters out.
Just use text[index]
to get at the needed character.
If you really need it as an array, use String.ToCharArray()
- you want an array of char
not an array of string
.
Edit:
Is it storing everything as a single item, and that's why the array only shows one place?
Yes, yes it is. You're making a list of string
s which contains one string
: the entire contents of text
- what it seems that you want is to split it up letter by letter, which is what the above methods will achieve.