954,514 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

instantiation in C#

class MyProgram
{
    static void Main()
    {
        int[] integers;            // declare array
        integers = new int[10];    // size array
    }
}


In which line is the array actually instantiated?

BioHazard90
Newbie Poster
11 posts since Nov 2008
Reputation Points: 5
Solved Threads: 0
 

Array get instantiated when you create it with new keyword:

integers = new int[10]; // size array

declaration can just create a reference.

int[] integers; // declare array

virang_21
Light Poster
29 posts since Jan 2009
Reputation Points: 10
Solved Threads: 2
 

integers = new int[10];

cVz
Junior Poster
140 posts since Mar 2008
Reputation Points: 29
Solved Threads: 7
 

Yep.. Just because you've declared a container, doesnt automagically mean its made, thefore the new keyword gives you the default contents for that type

LizR
Posting Virtuoso
1,791 posts since Aug 2008
Reputation Points: 196
Solved Threads: 190
 

int[] integers = new int[10];

her u put ur refrence in the stack pointed to integers[0] in the heap

BlackSun
Light Poster
46 posts since Feb 2008
Reputation Points: 28
Solved Threads: 5
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You