Purpose of ListToArray
BlitzMax Forums/BlitzMax Beginners Area/Purpose of ListToArray
| ||
The function 'ListToArray' seems so limited in its use.local list:tlist = new tList for local i:int = 1 to 5 list.addlast ("Apple Rules!") next local arrayS:string[] = string[] (list.toArray()) ' Result: arrayS=Null local arrayO:object[ = list.toArray() ' string( arrayO[0] ) works fine Is it supposed to work like this? Or is it somehow possible to convert the list directly in a string[]? Ghislain MacIntel OsX 10.4.7 |
| ||
It is supposed to work like this (return Array of Object -> :object[]) There is no way to directly return anything. Everytime you access the list, you have to cast object -> type as BM is a typesafe language so if you want to have an array of strings you have to cast all objects and add all objects that are actually strings to your string array. |
| ||
I wishstring[] (list.toArray()) would generate an Array with all the strings included in the list. I think that would be quite usefull. Probably not that difficult as well.. You could leave object[] (list.toArray()) for the cases you require objects... Ghislain MacIntel OsX 10.4.7 |
| ||
I must be missing something. Take the ToArray code and change the object to a string. Function tostringarray:String[](mylist:TList) Local n=mylist.count(),arr:String[n],i:Int For Local o:String=EachIn mylist arr[i]=o i:+1 Next Return arr End Function |
| ||
I'm sure some early versions could cast an entire array because some of my sourcecodes used it and it was only in later versions they stopped working. |