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>'
Member
9 Points
17 Posts
How to add a new item to the beginning of the list<T>
Jul 18, 2014 02:26 AM|garygold2|LINK
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
All-Star
101931 Points
20703 Posts
Re: How to add a new item to the beginning of the list<T>
Jul 18, 2014 02:32 AM|MetalAsp.Net|LINK
Use the Insert method instead of InsertRange.
Refer: http://msdn.microsoft.com/en-us/library/sey5k5z4(v=vs.110).aspx