c# - list.where 的编译错误

标签 c# list generics where-clause

我不明白为什么我总是收到这个错误。请帮忙!!!

“System.Collections.Generic.List”不包含“Where”的定义,并且找不到接受“System.Collections.Generic.List”类型的第一个参数的扩展方法“Where”(您是否缺少 using 指令或程序集引用?)

using System.Collections.Generic;
using System.Collections;
    public class HistTradePlot : Indicator
    {
        private class Traid
            {
                public DateTime Date { get; set; }
                public int Index { get; set; }
                public int Buy { get; set; }
                public int Price {get;set;}
            }
        List<Traid> traids = new List<Traid>();

            if (Bars.FirstBarOfSession)
                {Bars.Session.GetNextBeginEnd(BarsArray[0], 0, 
out sessionBegin, out sessionEnd);
                    var sessionTrades = traids.Where(t => t.Date > sessionBegin && t.Date <= sessionEnd);
                Print("Session Start: " + sessionBegin + " Session End: " + sessionEnd);
                for (int i=0;i<sessionTrades.Length();i++){
                Print(Convert.ToString(sessionTrades[i].Date));
                }
                }

最佳答案

这通常发生在您没有包含 Linq 命名空间时,因此编译器无法找到像 Where 这样的 Linq 扩展方法。尝试添加:

using System.Linq;

关于c# - list.where 的编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13390513/

相关文章:

ios - 如何声明具有符合协议(protocol)的具体返回类型的函数?

c# - 在 C# 中使用泛型属性

c# - 如何在 WCF soap 响应中实现安全 token ?

c# - 如何从 C# 中的文件名中删除目录字符串

python - 如何将字符串和列表的unicode组合到python列表

python - 获取固定大小的子列表

c# - 当 System.Security.Cryptography.ProtectedData 与可执行文件位于同一目录时,为什么我无法加载它

c# - ServiceStack 凭据 auth 端点给出 404

android - 单击 Android 中 Horizo​​ntalListView 内的项目

c# - Protobuf-net 不序列化泛型类型继承自泛型类型