Arrays in C# with Examples

Shahzad Aslam
2 min readMay 9, 2024

Array is such type of collection that have the capability to stores a fixed-sized elements of the same data type. But have the difference with mixed data types like Array List that can store mixed data types. In Array you can store multiple values of the same data type for example you can store multiple values of int data type of same variable and similarly In array you can also access multiple values of the same type under a single variable name.

Arrays in C# with Examples

The below we defined how you declare, initialize, and use arrays in C#:

Declaration and Initialization of Arrays:

Declaration:

You declare an array by specifying its data type, followed by square brackets [], and then providing a name for the array variable.

Example

// Declaration of an integer array
int[] numbers;

Initialization:

we can initialize an Array during it’s declaration. We can also assign existing array to it.

Example

// Initializing an integer array with values
int[] numbers = { 6, 2, 8, 2, 3 };
// Initializing an string array with values
string[] names = new string[3]; //A string Array that have fixed size of 3.

Accessing Array…

--

--

Shahzad Aslam

Welcome to c-sharptutorial.com. I am Shahzad Aslam. I am the founder of c-sharptutorial.com. I'm currently living near Islamabad, Pakistan.