gpt4 book ai didi

c# - C# 故障排除中最简单的 LINQ

转载 作者:行者123 更新时间:2023-11-30 21:21:00 25 4
gpt4 key购买 nike

我正在尝试学习一些 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);
}
}
}
}

错误是:

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'?

最佳答案

好吧,我们有一条错误消息,由 Microsoft 员工精心编写以提供帮助,让我们看一下。
找不到源类型“int[]”的查询模式的实现。找不到“选择”。您是否缺少对“System.Core.dll”的引用或“System.Linq”的使用指令?
int[] 是一种基本的 C# 类型。基本的 C# 类型位于何处?系统.核心。该错误提到检查对 System.Core 的引用。那么,是否有对 System.Core 的引用?
要检查这个:
解决方案资源管理器->引用。在列表中,您看到 System.Core 了吗?
如果不是,很奇怪,但它很容易添加。右键单击引用,在 .NET 下查找 System.Core,添加它,瞧。

关于c# - C# 故障排除中最简单的 LINQ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2967060/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com