0
0
C Sharp (C#)programming~5 mins

Single-dimensional array declaration in C Sharp (C#) - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is a single-dimensional array in C#?
A single-dimensional array in C# is a collection of elements of the same type stored in a linear sequence. It is like a row of boxes where each box holds one value.
Click to reveal answer
beginner
How do you declare a single-dimensional array of integers with 5 elements in C#?
You declare it like this: <br>int[] numbers = new int[5];<br>This creates an array named 'numbers' that can hold 5 integers.
Click to reveal answer
beginner
What does the number inside the square brackets mean in new int[5]?
It means the size of the array, or how many elements it can hold. Here, the array can hold 5 integers.
Click to reveal answer
beginner
How can you initialize a single-dimensional array with values at the time of declaration?
You can write: <br>int[] numbers = {1, 2, 3, 4, 5};<br>This creates an array with 5 elements and sets their values immediately.
Click to reveal answer
beginner
What is the index of the first element in a C# array?
The first element's index is 0. Arrays in C# are zero-based, so counting starts from 0.
Click to reveal answer
How do you declare a single-dimensional array of strings named 'names' with 3 elements in C#?
Astring[] names = new string[3];
Bstring names = new string[3];
Cstring[] names = string[3];
Dstring names[] = new string(3);
What is the index of the last element in an array declared as int[] arr = new int[10];?
A1
B9
C0
D10
Which of the following initializes an array with values 10, 20, 30 in C#?
Aint[] nums = new int[3] {10, 20, 30};
Bint nums[] = new int{10, 20, 30};
Cint[] nums = {10, 20, 30};
Dint nums = new int[3] {10, 20, 30};
What happens if you try to access an array element with an index outside its range?
AThe program ignores the request.
BIt returns null.
CIt returns the last element.
DYou get a runtime error called IndexOutOfRangeException.
Which keyword is used to create a new array instance in C#?
Anew
Bcreate
Carray
Dinit
Explain how to declare and initialize a single-dimensional array of integers with 4 elements in C#.
Think about the syntax: type[], name, new, size or values.
You got /3 concepts.
    Describe what zero-based indexing means in the context of C# arrays.
    Imagine counting boxes starting at zero.
    You got /3 concepts.