.net - Insert in VB List -


i have vb code below -

dim vals new list(of string)(7) vals.insert (0 , "a") vals.insert (1 , "b") vals.insert (2 , "c") vals.insert (5 , "e") 'here receive error index must within bounds of list.                       'parameter name: index 

in requirement have , need insert values @ specific indexes random insert. belive if set capacity of list should able insert values @ index withing capacity.

any idea missing?

the (7) in constructor specifying "initial capacity" of list, not initialising 8 elements. see msdn details

i think best option either:

1 - if "array" size not change (or not change often) use array instead

dim vals string() = new string(7) {}  'dim vals(7) string works not best practise vals(0) = "a" vals(3) = "d" 'etc. 

2 - initialise items in same line constructor

dim vals new list(of string)(enumerable.repeat("", 8)) vals(0) = "a" vals(3) = "d" 'etc. 

it seems me if want assign values @ arbitrary indexes using list poor choice.


Comments

Popular posts from this blog

matlab - "Contour not rendered for non-finite ZData" -

delphi - Indy UDP Read Contents of Adata -

javascript - Any ideas when Firefox is likely to implement lengthAdjust and textLength? -