|
I'd like to know how to initialize a generic list. Do I have to initialize the list somehow? I can't figure out how to initialize the list with placeholders.
(comments are locked)
|
|
Looks like your list is created, but empty.
(comments are locked)
|
|
You did initialize it; that's what " Maybe initialize is the wrong term. I'm trying to add a value at a specific position. I don't have values for positions 0,1,2,3 only 14. The other values will come in later.
Mar 06 '12 at 02:40 AM
dansav
The positions in a List don't exist until you add something. Sounds like you want to use
Mar 06 '12 at 02:45 AM
Eric5h5
I get an error when trying that: Cannot convert 'UnityEngine.String[]' to 'System.Collections.Generic.List.<UnityEngine.String>' I was hoping to be able to add values at certain positions and that other positions would be null and that I could check to see if a position has a value or is null.
Mar 06 '12 at 06:06 PM
dansav
string[] myArray = new string[15];
Mar 06 '12 at 06:10 PM
SirGive
The List"" is a first-in-first-out array. Using the Generics will cause it to start from zero and go from there. You would have to insert 14 other empty items into the list before getting to the 15th, where you could provide the value you are looking for. If you are looking for creating a known size array and you plan on using the last one as you need to, I think you'd be better off creating a standard array String[15] as Eric5h5 said. var mylist = new String[15]; myList[15] = "hello"; All of the other items will remain empty strings until you change them.
Mar 06 '12 at 06:12 PM
Jacob Aldridge
(comments are locked)
|
