int[] numbers = new int[10];
numbers[9] = 10;
Console.Write(numbers[^1] == numbers[numbers.Count()-1]); //true
How does index of ^1
returns the last item in an array?
What does ^1
mean in C# compiler?
Does it have performance benefit vs numbers[numbers.Count()-1]
?
numbers.Count()-1
sinceCount()
is a Linq method that needs to iterate through the entire array. – WeepingEnumerable.Count()
is a little smarter than that -- if applied to anything that implementsICollection
(which includes arrays) it will just get the.Count
of that. There's still overhead, but far less than if the whole array had to be iterated. – Unaccustomed^1
translated to? – Elsy