is this possible? I tried increasing the list capacity but that off course doesn’t resize and it seems an element always gets added to index 0 in an empty list, also with insert()
I want to use a list to run though chronological and use this order to play events according to their index nr. this list can be filled with events through a custom editorwindow , but i don’t wanna be stuck with making them in chronological order. in the editorwindow i can give the event a nr and that nr should be the events index place in the list.
how can i do that?
thx
J.
You should probably consider avoid using shorthand in future questions because I have no idea what an “nr” is.
But I guess you want to add items to a collection, but you want to have those items to be sorted in certain order based on a sequence number named “nr”.
If that is the case then try using a SortedDictionary with your objects as values and your nr’s as keys.
A SortedList is faster if you have an unsorted collection that you want sorted. SortedDictionary is faster for insertion and retrieval. Another option is to implement a Priority Queue. This article has a good one that uses a two-way heap and IComparable. I use it and it works great - the only thing it doesn’t do is re-sort if the priority on one of your items changes - but that’s straight forward to add yourself if you need it.
Alternately - if you’re not doing the sort often you can use LINQ to sort a regular List but this allocates enumerators.
thanks for the fast responds. why didn’t i think of that, i can sort my list afterwards… tsss.
anyway think I’ll go with the dictionary since i never used it before, this seems like a good opportunity.