- Home /
Trying to Sort a Multi Dimensional Array
I'm trying to sort a two dimensional array and I'm having a problem with the Unity syntax (or something).
I took this example from online and I thought it should work but I get an error in Unity.
int[,] array = new int[3, 3] { { 1, 4, 2 }, { 4, 5, 1 }, { 7, 3, 8 } };
int[,] sortedByFirstElement = array.OrderBy(x => x[0]);
int[,] sortedBySecondElement = array.OrderBy(x => x[1]);
int[,] sortedByThirdElement = array.OrderBy(x => x[2]);
When I run it I get error message CS0411 which says: "...Try specifying the type arguments explicitly"
How do I need to modify/change this so I can get it to work in Unity?
Thank you in advance.
Answer by Bunny83 · Apr 09, 2018 at 01:55 AM
You probably found this post and just like others which commented on that page you didn't seem to read the post that was mentioned in that answer. The built-in linq extensions do not support multidimensional arrays. You have to write your own extension or use the one provided on the codeproject post.
Thanks for taking the time to help me. I did see the post that you mentioned above although I'm not sure that is how I interpreted it. I will certainly look at that again. I'll consider perhaps a bubble sort or something else.
By the way, I saw some "Bunny83" videos on the Internet. Wow. Those are really, uh, entertaining. Are those you? In any event, thanks again for your kind help.
Uhm, I usually don't create any "videos". The only two videos i've ever uploaded are on my YT channel ^^. I've created some animated gifs but only for answers here on UA (like this, this or this for example)
Sorry, "Bunny83" is a fairly unique name and I thought they might be yours. Thanks again though. You've been very helpful to me and I appreciate you taking the time to respond. Best wishes in the future.