Back to questions
JuniorTheoryCommon
What does the program print (lines separated by spaces)?
int[] a = [10, 20, 30, 40, 50];
int[] part = a[1..3];
part[0] = 99;
Console.WriteLine(a[^1]);
Console.WriteLine(part.Length);
Console.WriteLine(a[1]);50 2 20
- Expecting
50 3 20: the end of a range is not included, soa[1..3]holds only the elements at indexes1and2. - Expecting
99or40: a range of an array is a new array, sopart[0] = 99leavesaalone, and^1is the last element, not the one before it.
- What does
a[^2..]hold for the same array? - What happens if the program prints
a[^0]?