我有一个 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;
...
}
}
这会导致以下错误:
(parameter)
IEnumerable<CellDiff> diffs
Error:
Could not find an implementation of the query pattern for source type 'CellDiff
'. 'Where
' not found.
我也试过 diffs.AsQueryable()
, 无济于事。
我在 IEnumerable<T>
上执行 LINQ 查询通常没有问题.我对这里发生的事情有点迷茫。
最佳答案
在 LINQ 查询语法中指定类型会创建对带有该类型参数的 Cast
扩展方法的调用。
您是否在某处定义了自己的Cast
?
关于c# - 无法在 IEnumerable<T> 上找到查询模式的实现,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13045470/