BrickInTheWall
07-11-2009, 11:20 PM
Hi everyone,
I'm a bit confused...I'm learning C# right now and was just reading through a tutorial about arrays as things have changed a bit (especially since there are no pointers allowed in safe code)...
My book tells me to declare the array like so (c#):
int[] myIntArray;
myIntArray = new int[5];
of course, I'm used to declaring arrays the standard C/C++ way
int myIntArray[5];
but what confuses me is the use of the 'new' keyword in the C# declaration. I'm used to doing that in C++ when I want to allocate memory on the free store for the array like so:
int* myIntArray;
myIntArray = new int[5];
this would usually require me to deallocate the memory after I'm done with it right? (like in the destructor of a class for example) using delete[]...
My book doesn't even mention this...can somebody please clear things up for me a little here? Its also kinda of weird for me not to be using a pointer to declare the array since...in a strict sence...thats what it basically is.
Cheers,
Chris
I'm a bit confused...I'm learning C# right now and was just reading through a tutorial about arrays as things have changed a bit (especially since there are no pointers allowed in safe code)...
My book tells me to declare the array like so (c#):
int[] myIntArray;
myIntArray = new int[5];
of course, I'm used to declaring arrays the standard C/C++ way
int myIntArray[5];
but what confuses me is the use of the 'new' keyword in the C# declaration. I'm used to doing that in C++ when I want to allocate memory on the free store for the array like so:
int* myIntArray;
myIntArray = new int[5];
this would usually require me to deallocate the memory after I'm done with it right? (like in the destructor of a class for example) using delete[]...
My book doesn't even mention this...can somebody please clear things up for me a little here? Its also kinda of weird for me not to be using a pointer to declare the array since...in a strict sence...thats what it basically is.
Cheers,
Chris