Jamie Dixon
Jamie Dixon

Reputation: 54011

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?

Upvotes: 0

Views: 222

Answers (1)

dtb
dtb

Reputation: 217371

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.

Upvotes: 9

Related Questions