代码之家  ›  专栏  ›  技术社区  ›  Jay

C中最简单的LINQ故障排除

  •  2
  • Jay  · 技术社区  · 16 年前

    我正在尝试学习一点LINQ,但是我马上就遇到了编译问题。有没有什么具体的原因让这不起作用?

    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);
                }
            }
        } 
    }  
    

    错误是:

    2 回复  |  直到 16 年前
        1
  •  2
  •   Rubys    16 年前

    好吧,我们有一条错误消息,是由一位微软员工精心编写的,希望对您有所帮助,所以让我们看看它。
    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'?
    int[] 是基本的C型。基本的C类型在哪里?系统核心。错误提到检查对System.Core的引用。那么,有没有提到系统核心?

    解决方案资源管理器->参考文献。在列表中,你看到System.Core了吗?

        2
  •  2
  •   JaredPar    16 年前

    你在你的项目中有没有提到System.Core?其他都是对的。