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

Array methods (Sort, Reverse, IndexOf) in C Sharp (C#) - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to sort the array in ascending order.

C Sharp (C#)
int[] numbers = {5, 3, 8, 1};
Array.[1](numbers);
Drag options to blanks, or click blank then click option'
AIndexOf
BReverse
CSort
DFind
Attempts:
3 left
💡 Hint
Common Mistakes
Using Reverse instead of Sort will flip the array but not sort it.
IndexOf is used to find an element, not to sort.
2fill in blank
medium

Complete the code to reverse the order of elements in the array.

C Sharp (C#)
string[] fruits = {"apple", "banana", "cherry"};
Array.[1](fruits);
Drag options to blanks, or click blank then click option'
AReverse
BSort
CIndexOf
DClear
Attempts:
3 left
💡 Hint
Common Mistakes
Using Sort will reorder elements, not reverse them.
IndexOf is for searching, not changing order.
3fill in blank
hard

Fix the error in the code to find the index of the element "dog" in the array.

C Sharp (C#)
string[] animals = {"cat", "dog", "bird"};
int index = Array.[1](animals, "dog");
Drag options to blanks, or click blank then click option'
ASort
BFindIndex
CReverse
DIndexOf
Attempts:
3 left
💡 Hint
Common Mistakes
Using Sort or Reverse will not find an element's index.
FindIndex is a method for lists, not arrays.
4fill in blank
hard

Fill both blanks to sort the array and then reverse it.

C Sharp (C#)
int[] values = {4, 7, 2, 9};
Array.[1](values);
Array.[2](values);
Drag options to blanks, or click blank then click option'
ASort
BClear
CReverse
DIndexOf
Attempts:
3 left
💡 Hint
Common Mistakes
Reversing before sorting will not produce descending order.
Using Clear or IndexOf here is incorrect.
5fill in blank
hard

Fill all three blanks to find the index of "blue" in the colors array after sorting and reversing it.

C Sharp (C#)
string[] colors = {"red", "blue", "green"};
Array.[1](colors);
Array.[2](colors);
int pos = Array.[3](colors, "blue");
Drag options to blanks, or click blank then click option'
ASort
BIndexOf
CReverse
DClear
Attempts:
3 left
💡 Hint
Common Mistakes
Trying to find the index before sorting and reversing.
Using Clear instead of Reverse or IndexOf.