https://dotnetfiddle.net/QHd0Rr#
I'm trying to populate a simple IEnumerable but I'm getting an error:
Unhandled exception. System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')
at System.Collections.Generic.List`1.get_Item(Int32 index)
at Program.Main()
Command terminated by signal 6
using System;
using System.Linq;
using System.Collections.Generic;
public class Program
{
public static void Main()
{
var key1 = new WidgetA{Id = 1, Key = 52};
var key2 = new WidgetA{Id = 1, Key = 102};
var key3 = new WidgetA{Id = 1, Key = 152};
IEnumerable<WidgetA> list = Enumerable.Empty<WidgetA>();
list.Append(key1);
list.Append(key2);
list.Append(key3);
Console.WriteLine(list.ToList()[0]);
}
}
public class WidgetA
{
public int Id { get; set; }
public int Key { get; set; }
public string ValueToGet { get; set; }
}