• Advertisement
Sign in to follow this  

C# arrays

This topic is 3213 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am tested out c#. It seems as if in comparison to C and C++, you can't declare an array on the stack like this int array[100]; I have to do this instead int[] array; array=new int[100]; Why does it require dynamic memory allocation? [Edited by - V-man on May 3, 2009 3:22:56 PM]

Share this post


Link to post
Share on other sites
Advertisement
Basically, because arrays are reference types, not value types.

Share this post


Link to post
Share on other sites
Heap allocation doesn't have to be quite as bad in C# as C++ however. Modern managed languages can take advantage of a number of optimisations which can make dynamic allocation relatively cheap and garbage collection relatively quick for short lived objects.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement