Dynamic memory allocation for an array

  • Thread starter Thread starter Vicky
  • Start date Start date
V

Vicky

I need to know how to set the size of an array at runtime (ie) a[]
should have the its size increased/decreased as its contents are added/
deleted. Can u tell me how to do it?
 
should have the its size increased/decreased as its contents are added/
deleted. Can u tell me how to do it?

Arrays are not resizeable once created; use a List<T> - i.e.
List<int> list = new List<int>();
list.Add(123);
list.Add(456);

if you need an array (copy) from this, call ToArray().

Marc
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top