none
Could not find an implementation of the query pattern for source type 'string[*,*]'. 'OrderBy' not found. RRS feed

  • General discussion

  • I get a compile error on the "array" in the LINQ. I'm on .NET 4.5, VS 2010.

    Could not find an implementation of the query pattern for source type 'string[*,*]'. 'OrderBy' not found. Are you missing a reference to 'System.Core.dll' or a using directive for 'System.Linq'?

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;


    namespace Test2dArraySortLINQ
    {
        class Program
        {
            static void Main(string[] args)
            {
                string[,] array = new string[,] 
                {  
                    {"12", "Animal", "Cat"},
                    {"20", "Animal", "Dog"},
                    {"6", "Vegetable", "Carrot"},
                    {"5", "Mineral", "Iron"}
                };

                var sorted = (from x in array
                              orderby x[1]
                              select x).ToArray();
            }
        }
    }

    


    Steven R. Sparks

    I found the answer in another forum but I thought it may be helpful to provide the answer:

    In order to use a multidimensional array with LINQ, you need to convert it to IEnumerable<T>. 

    Typing "x" with "string" accomplishes this:

    var sorted = (from string x in array
                              orderby x[1]
                              select x).ToArray()

    Sunday, June 30, 2013 10:46 PM

All replies