c# - 即使包含 System.Core.dll 也无法访问 System.Linq
问题描述
我有这个控制台应用程序:
namespace LinqTestFramework
{
using System.Collections.Generic;
public class Program
{
static void Main(string[] args)
{
var dict = new Dictionary<int, string>()
{
{ 1, "David" }
};
} //breakpoint set here: Watch window: System.Linq.Enumerable.Where(dict, x => true)
}
}
namespace LinqTestFramework
{
using System.Linq;
public class SomeClass
{
public void SomeMethod()
{
var valuesBelowFour = Enumerable.Range(0, 10).Where(x => x < 4);
}
}
}
我可以从 ILSpy 中看到包含这些方法的 System.Core dll:
我试图在调试期间从 Watch 窗口运行以下命令:
System.Linq.Enumerable.Where(dict, x => true)
但我收到了这个错误:
错误 CS0234:命名空间“System”中不存在类型或命名空间名称“Linq”(您是否缺少程序集引用?)
为什么我无法访问 中的扩展方法System.Linq.Enumerable
?
解决方案
似乎它需要一个使用 Linq 方法来加载它的方法调用。所以我尝试了下面的代码,现在它正在工作
public class Program
{
static void Main(string[] args)
{
var dict = new Dictionary<int, string>()
{
{ 1, "David" }
};
var n = dict.Keys.Select(x=>x);
} //breakpoint set here: Watch window:
}
推荐阅读
- javascript - WebStorm 无法识别 Semantic-ui-vue 组件
- php - 在没有作曲家的情况下安装干预图像
- sql-server - 同一服务器上的 Azure SQL 数据库会影响彼此的性能
- c# - 冒泡NotifyPropertyChanged
- react-native - 在 React Native 中动态添加属性
- regex - 如何将记事本++中的3级线转换为csv
- python - 模拟请求时如何从aiohttp中的路由获取动态路径参数?
- request - Symfony 3.4:如何在树枝模板中模拟 app.request
- mysql - 从 MySQL 数据库创建 CSV 并附加到 PHPMailer 电子邮件
- excel-formula - Excel:如果数据点共享同一行,如何求和?