By Team Escalera
on 31 Oct 2017 02:58 PM
  • learn C#

This post is helpful if the task is : Providing Initial Values to an Array.

When an array is declared by using curly brackets we can provide initial values to it :

string[ ] cities= new string[3] {“Delhi”, “Mumbai”, “Lucknow”};

We can omit the size declaration when the number of elements are provided in the curly braces:

string[ ] cities= new string[ ] {“Delhi”, “Mumbai”, “Lucknow”};

The new operator can be omitted as well.The example given below will work the same as other two options given above.

string[ ] cities= {“Delhi”, “Mumbai”, “Lucknow”};

We can declare array of strings, integers or any other data type.

Remember – In this case the number of elements are provided comma separated in the curly braces .

Comments (0)

Leave A Comment