0

Hello, I am thinking about doing a matrix RREF function, am still in the research stage, but I thought I should post a bug I have been having. The following code doesn't work. What I am trying to do is orderby the array index [0], and then by [i...] etc. Here is the code I have been having trouble with. I am trying to break the orderby decending, and thenby operations up onto multiple lines as I build the query so I can have a looping like action. I think it doesn't matter which rows you swap in RREF as long as the row with the 0 on the front is at the bottom, and the larger numbers are at the top, but I could be wrong, it has been a while since I had a math class, and I am going to have to sift through my books. I may be attempting to break some LINQ rules here, I don't know. Please enlighten me as I am new to LINQ.

        public static IEnumerable<int[]> OrderByMatrixRows(this int[][] jagged) {

            IEnumerable<int[]> query = jagged.OrderByDescending(row => row[0]);
            for (int i = 1; i < jagged.Length; i++) {

                //the following line errors out
                query = query.ThenBy(row => row[i]);
            }//end loop

            return query;

        }//end method

If I can't do this with LINQ I will have to figure out some other way of doing so. Also if you all have any good sources for re-learning RREF please post em.

1
Contributor
1
Reply
14
Views
2 Years
Discussion Span
Last Post by overwraith
0

I figured it out, sorry guys. My variable statement was casting it to something that I should have known not to cast it to, you see when you link together an orderbydecending it returns an IOrderedEnumerable, not an IEnumerable. So it was casting it to something that was essentially unordered. I admonish myself to always use var in linq queries from now on because the var statement fixes this particular problm.

        public static IEnumerable<int[]> OrderByMatrixRows(this int[][] jagged) {

            var query = jagged.OrderByDescending(row => row[0]);
            for (int i = 1; i < jagged.Length; i++) {
                query = query.ThenBy(row => row[i]);
            }//end loop

            return query;

        }//end method
This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.