Int[] Reverse - What does this actually do?
I was just having a play around with some code in LINQPad and noticed that on an int array there is a Reverse method.
Usually when I want to reverse an int array I'd do so with
Array.Reverse(myIntArray);
Which, given the array {1,2,3,4}
would then return 4
as the value of myIntArray[0]
.
When I used the Reverse()
method directly on my int开发者_如何转开发 array:
myIntArray.Reverse();
I notice that myIntArray[0]
still comes out as 1
.
What is the Reverse
method actually doing here?
myIntArray.Reverse()
is the extension method Enumerable.Reverse which returns an IEnumerable<int> of the reversed array elements. It does not modify the array in-place as it Array.Reverse does.
精彩评论