Rik
Rik

Reputation: 1987

Compile Error for list.where

I can't figure out why I keep getting this error. Please help!!!

'System.Collections.Generic.List' does not contain a definition for 'Where' and no extension method 'Where' accepting a first argument of type 'System.Collections.Generic.List' could be found (are you missing a using directive or an assembly reference?)

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));
                }
                }

Upvotes: 3

Views: 2102

Answers (3)

cebert
cebert

Reputation: 71

Also, LINQ is in Frameworks 3.5 and later. If you are using a version of .NET that is before 3.5, LINQ isn't supported.

Upvotes: 3

Daniel A. White
Daniel A. White

Reputation: 190943

You need to have

using System.Linq;

at the top of your file.

Upvotes: 5

McGarnagle
McGarnagle

Reputation: 102753

This usually happens when you haven't included the Linq namespace, so the compiler can't find the Linq extension methods like Where. Try adding:

using System.Linq;

Upvotes: 6

Related Questions