- Home /
What the heck is a 'function(System.Array): void' Type?
I posted this a couple of months ago: I can't see a reason for this Array.Reverse() error. In brief, trying to Reverse a color array in UnityScript returned an IENumerable and I needed to convert it to an array to use it as one…
var test2 = test.Reverse().ToArray();
This was working fine but after updating to the latest version of Unity and MonoDevelop, it's now broken and I'm getting some weird errors…
First error: BCE0023: No appropriate version of 'System.Array.Reverse' for the argument list '()' was found. — Solved by removing the brackets on the end of Reverse
but…
var test2 = test.Reverse.ToArray();
Second error: BCE0019: 'ToArray' is not a member of 'function(System.Array): void'. — Maybe it's converted to an Array directly in the new MonoDevelop and I don't need to convert? So I remove the ToArray()
section…
var test2 = test.Reverse;
Third error: BCE0048: Type 'function(System.Array): void' does not support slicing. — So I can't access it as an array…
It seems they've changed some underlying code structure in MonoDevelop. Any ideas on a fix?
I don't know if this is a stupid question, but did you try it using LINQ?
Ooh, not a stupid question — I didn't think of that actually. LINQ does appear to work fine.
Answer by ArkaneX · Feb 03, 2014 at 07:42 PM
Agree with Kiloblargh comment - Reverse (without parameters) is a LINQ extension method, and you problably don't have
using System.Linq;
in your code.
I guess that without this 'using', Unity compiler thinks you want to use Reverse method of System.Array class. This is a static void method, accepting System.Array parameter, and hence the compiler errors you see.
Yep, Linq does fix the issue. Although I don't understand why it worked previously and suddenly broke.
Hmm I've just checked the tags in your question and see that you use javascript. I generally use C#, but from time to time I do some test using JS as well. I once observed, that adding import System.Linq;
to any of your JS scripts works for all scripts in the project. $$anonymous$$aybe this worked in one of previous Unity versions, and now has been changed? Or maybe you simply removed the script containing this line?
Your answer
Follow this Question
Related Questions
Javascript / Unityscript adding elements of an array 2 Answers
Referencing data in pre-defined array 1 Answer
JavaScript 3 Arrays questions 1 Answer
Why can't I push and pop from string array? 1 Answer
Is IsNan not IsInfinity ?? 4 Answers