How to Declare an Array in C#?

How do you declare and initialize an array in C#(CSharp) Programming Language?

CSharp Array Declaration, Initialization

Arrays are variables used to store similar data types grouping as a single unit. It is the collection of variables of the same type stored at contiguous memory locations. The lowest memory address corresponds to the first element and the highest memory address to the last element. C# (CSharp) is a multiparadigm programming language. This step by step tutorial will help you to learn how to declare an array in C# (CSharp) Programming language.
How To Declare Array In Csharp
C# Array Declaration :
Syntax :
data_type[] arrayName;
data_type is the type of elements in the array.
[ ] specifies the rank of the array, i.e., the size of the array.
arrayName specifies the name of the array.
Csharp Array Declaration Syntax
Example of an array declared in C#
double[] balance;
C# Array Initialization:
Declaring an array does not initialize the array in the memory. You can assign values to the array only when the array variable is initialized. Array is a reference type, so you need to use the "new" keyword to create an instance of the array, that is to initialize the array.

For example,
double[] balance = new double[10];
Csharp Array Initialization Syntax

Related Topics