c# - 无法在 IEnumerable<T> 上找到查询模式的实现

标签 c# linq compiler-errors ienumerable

我有一个 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/

相关文章:

javascript - 在 Xamarin 中从 C# 对象调用 JavaScript

c# - 是否可以在同一个解决方案中为 Windows 8.1 桌面和商店应用程序开发?

c# - 从对象获取属性信息而不将属性名称作为字符串提供

c# - LINQ:如何根据上下文修改 AsParallel 的返回类型?

c# - 让 SequenceEqual 为列表工作

c# - 使用 Linq Where 子句时返回对象的问题

c# - 是否可以通过 Microsoft Bot Framework 自定义 Teams 中接收到的图像和 GIF 的大小

c# - 如何在 Visual Studio 2015 中将 c# csproj 编译为 exe - 错误 CS0579

c++ - 为什么GCC会说 “a function-definition is not allowed here before ' {' token”?

iphone - 我的Xcode-编译错误只是显示红色的感叹号