An array of lists

Monkey Forums/Monkey Programming/An array of lists

Oddball(Posted 2013) [#1]
Hello. I would like to make an array of 16 lists. Could someone explain how this is achieved? Thank you.


therevills(Posted 2013) [#2]
Something like this:
Strict

Function Main:Int()
	Local arrayOfList:List<String>[16]
	For Local i:Int = 0 Until arrayOfList.Length()
		arrayOfList[i] = New List<String>
		If i = 1
			arrayOfList[i].AddLast("1")
			arrayOfList[i].AddLast("2")
		End
	Next
	For Local s:String = Eachin arrayOfList[1]
		Print s
	Next
	Return 0
End


* Updated code - Thanks Jesse


Jesse(Posted 2013) [#3]
@therevills
don't you mean:
	Local arrayOfList:List<String>[16]



therevills(Posted 2013) [#4]
Nope, arrays are zero bases, so declaring 15 elements gets you 16 lists. Blah Blah Blah :D


Jesse(Posted 2013) [#5]
check again.
Strict

Function Main:Int()
	Local arrayOfList:List<String>[15]
	For Local i:Int = 0 Until arrayOfList.Length()
		arrayOfList[i] = New List<String>
		If i = 1
			arrayOfList[i].AddLast("1")
			arrayOfList[i].AddLast("2")
		End
	Next
	For Local s:String = Eachin arrayOfList[15]
		Print s
	Next
	Return 0
End



Monkey Runtime Error : Array index out of range




c.k.(Posted 2013) [#6]
Doesn't declaring 15 elements get you 15 elements (0..14)?

[monkeycode]
For Local s:String = Eachin arrayOfList[14]
Print s
Next
[/monkeycode]

That shows you the last list.


Jesse(Posted 2013) [#7]
^^ correct!


therevills(Posted 2013) [#8]
Hahahaha... my bad - Can I go home now :)

(Sorry!)


Jesse(Posted 2013) [#9]
take the rest of the day off. you've been working too hard. :)


Samah(Posted 2013) [#10]
That made my day. :D
/slap therevills


therevills(Posted 2013) [#11]
/slap therevills

I was waiting for you to make a reply! LOL!

Leave me alone - "they" want to make IVR active / active with TMS!!!!


Oddball(Posted 2013) [#12]
Thank you. I shall attempt this later today.