Establishing Array Size

  • Thread starter Thread starter Jim Heavey
  • Start date Start date
J

Jim Heavey

What is the correct format for establishing the size of an array which you
will populate later?

I tried

string[5] myArray;

Does not seem to like this...
 
Jim Heavey said:
What is the correct format for establishing the size of an array which you
will populate later?

I tried

string[5] myArray;

To declare the reference variable that can be attached to an array instance
later:
string [] myArray;

Same as above, and create an instance of an array which can hold strings:
string [] myArray = new string [5];

To create an instance of an array that holds 5 strings:
string [] myArray = new string [5] { "bob", "sue", "phil", "rex", "tony" };

Or the equivalent:
string [] myArray = new string [] { "bob", "sue", "phil", "rex", "tony" };
 
Back
Top