I need to declare an empty string array and i\'m using this code
string[] arr = new String[0]();
But I get \"method name expected\" error.<
Your syntax is invalid.
string[] arr = new string[5];
That will create arr
, a referenced array of strings, where all elements of this array are null
. (Since strings are reference types)
This array contains the elements from arr[0]
to arr[4]
. The new
operator is used to create the array and initialize the array elements to their default values. In this example, all the array elements are initialized to null
.
Single-Dimensional Arrays (C# Programming Guide)