Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
What are Arrays? | Arrays
course content

Зміст курсу

C# Basics

What are Arrays?What are Arrays?

Consider a situation where we need to store the subject marks of 50 students. One way is to make 50 integer variables that hold the marks of 50 students ,however it is very tedious and in-efficient. Instead, we can create an Array.

An Array is like a collection of variables of the same type. We can create an array using the following syntax:

cs

main.cs

The datatype indicates the type of elements the array will possess, it can be int, float, char etc, while size is the number of elements the array will have.

Using the above syntax we can create an integer array having 50 elements:

cs

main.cs

The size of an array is fixed and cannot be changed. In case we want to initialize an array with some elements at the time of declaration, we can use the following syntax:

cs

main.cs

In this case we don't need to specify the size of the array. It is automatically inferred by the compiler based on the number of elements the array is initialized with. For-example:

cs

main.cs

The size of the above array is 7 since it is initialized with seven elements. This size stays fixed throughout the program.

Following is an illustration of a string array that has 4 elements:

Each element is like a box which contains a value, and that value can be changed.

Which of the following can be changed about an array?

Виберіть правильну відповідь

Все було зрозуміло?

Секція 5. Розділ 1
course content

Зміст курсу

C# Basics

What are Arrays?What are Arrays?

Consider a situation where we need to store the subject marks of 50 students. One way is to make 50 integer variables that hold the marks of 50 students ,however it is very tedious and in-efficient. Instead, we can create an Array.

An Array is like a collection of variables of the same type. We can create an array using the following syntax:

cs

main.cs

The datatype indicates the type of elements the array will possess, it can be int, float, char etc, while size is the number of elements the array will have.

Using the above syntax we can create an integer array having 50 elements:

cs

main.cs

The size of an array is fixed and cannot be changed. In case we want to initialize an array with some elements at the time of declaration, we can use the following syntax:

cs

main.cs

In this case we don't need to specify the size of the array. It is automatically inferred by the compiler based on the number of elements the array is initialized with. For-example:

cs

main.cs

The size of the above array is 7 since it is initialized with seven elements. This size stays fixed throughout the program.

Following is an illustration of a string array that has 4 elements:

Each element is like a box which contains a value, and that value can be changed.

Which of the following can be changed about an array?

Виберіть правильну відповідь

Все було зрозуміло?

Секція 5. Розділ 1
some-alt