I have the same problem that IList<int> throws Null Reference Exception when adding values, and the solution is initialize the list field in the constructor with "new List();", but in my program I have a structure, no a class. What can I do with C# if the structures in C# are parameterless?
public struct ListStruct<T> : IEnumerable<T>, IList<T>
{
private List<T> value;
//public ListStruct()
//{
// this.value = new List<T>();
//}
// ...
public void Add(T item)
{
((IList<T>)value).Add(item); // Execution time: NullReferenceException was unhandled
}
}