Syntax of Value Assignment with Initialization in C#
This topic contains and tries to cover following subjects:
- Syntax of Value Assignment with Initialization
- Detailed C# Array example has been provided in C# Language section.
Articles provides answer to following questions and issues:
- How to assign values to all elements of an array with array Initialization in C#?
Syntax of Array element value assignment with Initialization in C#
Array elements can be assigned in its initialization for easier assignment. Syntax of Array element assignment in initialization is as follows:
-Type- [] -variableName- = new -Type- [no size is Required] {-values- separated by comma};
Example of Array Value Assignment with Initialization in C#
Following example shows array declaration and value assignment with initialization in C#. In that initialization method, size is not required to be provided. Compiler knows the size from assigned elements, generates automatically.
string [] v_arr_places = new string [] {"nebraska","nevada","brooklyn"};