The understanding of C # one-dimensional arrays before we look at what is an array? An array is a collection of several variables of the same type that can be referenced with the same name. Arrays are composed of contiguous storage units, the lowest address corresponds to the first element of the array, the highest address corresponds to the last element, and the array can be one-dimensional or multidimensional.
A one-dimensional array is essentially a table-one-dimensional array of similar data
You can declare an array of 5 integers as shown in the following example:
int[] array = new INT[5];
This array contains elements from array[0] to array[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 zero.
You can declare an array of stored string elements in the same way. For example:
string[] stringArray = new string[6];
Initialization of a C # one-dimensional array
You can initialize an array when it is declared, in which case the level specifier is not required because the level specifier is already provided by the number of elements in the initialization list. For example:
int[] array1 = new Int[5] {1, 3, 5, 7, 9};
You can initialize an array of strings in the same way. The following declares a string array in which each array element is initialized with the name of the day:
string[] weekDays =
new string[] { "Sun", "Mon", "Tue",
"Wed", "Thu", "Fri", "Sat" };
If you initialize an array when it is declared, you can use the following shortcuts:
int[] array2 = { 1, 3, 5, 7, 9 };
string[] weekDays2 = { "Sun", "Mon",
"Tue", "Wed", "Thu", "Fri", "Sat" };
You can declare an array variable without initializing it, but you must use the new operator when assigning an array to this variable. For example:
int[] array3;
array3 = new int[] { 1, 3, 5, 7, 9 }; // OK
//array3 = {1, 3, 5, 7, 9}; // Error
The concepts and contents of the initialization of a C # one-dimensional array are introduced here to help you understand and learn the initialization of a C # one-dimensional array.