【发布时间】:2012-10-14 06:31:45
【问题描述】:
我有一个IEnumerable<T> 作为方法的参数,其中T 是一个结构类型:
using System;
using System.Collections.Generic;
using System.Linq;
using ...
public static class Foo
{
internal struct CellDiff
{
public int RefX;
public int RefY;
public object OldValue;
public object NewValue;
}
private static void ItemChanged(IEnumerable<CellDiff> diffs, int cellX, int cellY)
{
var change = from CellDiff diff in diffs
where diff.RefX == cellX && diff.RefY == cellY
select diff;
...
}
}
这会导致以下错误:
(参数)
IEnumerable<CellDiff> diffs错误:
找不到源类型“CellDiff”的查询模式的实现。 'Where' 未找到。
我也尝试过diffs.AsQueryable(),但无济于事。
我在IEnumerable<T> 上进行 LINQ 查询通常没有问题。我对这里发生的事情有点迷茫。
【问题讨论】:
-
您确定错误出现在代码的那部分吗?除了查询变量上的冗余类型之外,它似乎很好
-
我刚刚尝试了您的代码并且它工作正常。似乎错误在其他地方。
-
@RuneFS 100% 确定。如果我添加类型,则会出现错误,如果我删除它,错误就会消失。
-
您是否在 select 或 Cast 上实现了自己的扩展方法?
-
这是什么版本的 .NET / 编译器?还加载了哪些其他库?我想知道另一个库是否正在将内容添加到 System.Linq 或“...”中的另一个命名空间中
标签: c# linq compiler-errors ienumerable