Click here to Skip to main content
15,888,401 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
how to add values into array dynamically


could you please provide me code?
Posted

1 solution

I assume your intention is to grow an array by one or more indices - that's not possible. You would have to allocate a new array that has the desired size and copy the values of the old array into it. See Array.Copy(..)[^]

Maybe you should consider using one of the standard Collection-Classes instead, like List<t>[^] or whatever would suit you. Those would handle growing the underlying storage automatically.
 
Share this answer
 
v2
Comments
Sergey Alexandrovich Kryukov 7-Mar-15 16:55pm    
Correct, 5ed. I think the intention to add elements to the array was clear enough, as it would be hard to understand the word "add" in other way.
—SA
[no name] 7-Mar-15 16:57pm    
Thank you. And yeah, you're probably right.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900