locked
How to add a new item to the beginning of the list<T> RRS feed

  • Question

  • User-772104780 posted

    Hi,
    I have
    public struct Bar     
    {
        public double Time  { get; set; }
        public double Open  { get; set; }
        public double Close { get; set; }
     }

    public class Bars
    {        
        public static List<Bar> list = new List<Bar>();
    }

    My app

      Bars.list.Add(new Bar() { Time = 13123121, Open = 1.2345, Close =1.3456 });   // it's OK

    then I need to add a new item to the beginning of the list

    Bar newBar = new Bar() { Time = 13123555, Open = 1.2375, Close =1.3457 });

    Bars.list.InsertRange(0, newBar);  
    // error   The best overloaded method match for 'System.Collections.Generic.List<Bar>.InsertRange(int, System.Collections.Generic.IEnumerable<Bar>)' has some invalid arguments  
    or
    Bars.list.InsertRange(0, (IEnumerable<Bar>)newBar);
    // error Cannot convert type 'Bar' to 'System.Collections.Generic.IEnumerable<Bar>'

    Thanks

                 




    Friday, July 18, 2014 2:26 AM

Answers