IEnumerable<T> Queue.Count is not returning an integer RRS feed

  • Question

  • I am attempting to define a queue named movingAverages with a size of queue.Count - period.  I am getting an error "int IEnumerable<DateClose>.Count<DateClose>() ... - cannot be applied to method and int....        

    private static IEnumerable<DateClose> MovingAverage(
                IEnumerable<DateClose> queue, int period)
                Queue<DateClose> movingAverages = new Queue<DateClose>(queue.Count + period);
                return movingAverages;
    Thursday, November 15, 2018 8:50 PM


  • IEnumerable does not have a Count property, but there is a Linq extension method. This means you have to put parentheses after it, so the compiler knows it's a method.

    Queue<DateClose> movingAverages = new Queue<DateClose>(queue.Count() + period); // Put "()" after Count.

    • Marked as answer by DoctorWhoKnew Thursday, November 15, 2018 10:48 PM
    Thursday, November 15, 2018 10:36 PM