I can't see a reason for this Array.Reverse() error

I’m trying to reverse the array of pixel information, but the Reverse() command gives a runtime error that it “Cannot cast from source type to destination type.” but they’re both Color arrays! What’s going on?

   var texture : Texture2D;
    
    function Start () {
        var test : Color[] = texture.GetPixels();
        var test2 : Color[] = test.Reverse();
    }

Reverse returns void, the change is applied directly to the array (in this case, “test”).

If you don’t need “test” for anything else, you can simply replace line 5 with:

test.Reverse();

If you do need it, you should make a copy of “test” before applying the Reverse method.

I think you are supposed to use it like this:

System.Array.Reverse(test);

I don’t think you need to assign it to another variable.

WOW. So after exhaustive testing I discovered Reverse() doesn’t actually return an array, it returns an IENumerable! Crazy! It’s fixed by converting to an array after reversing…

var test2 = test.Reverse().ToArray();