Simplest LINQ in C# troubleshooting.

Posted by Jay on Stack Overflow See other posts from Stack Overflow or by Jay
Published on 2010-06-03T14:52:14Z Indexed on 2010/06/03 14:54 UTC
Read the original article Hit count: 193

Filed under:
|
|

I'm trying to learn a bit of LINQ but I'm having compile issues right off the bat. Is there any specific reason why this won't work?

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

namespace HelloLINQ {

   class HelloLINQ
   {
       public static void Main()
       {
           Example1();
       }


       public static void Example1()
       {
           var numbers = new int[] { 1, 5, 3, 7, 3, 8, 9, 3, 6, 6, 2 };
           var under5 = from n in numbers
                        select n;
           foreach (var n in under5)
           {
               Console.WriteLine(n);
           }
       }
   } 

}

The error is:

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

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ