I have this code :
IList<string> stelle = stelleString.Split('-');
if (stelle.Contains("3"))
stelle.Add("8");
if (stelle.Contains("4"))
stelle.Add("6");
but seems that IList have a fixed size after a .Split() : System.NotSupportedException: Collection was of a fixed size.
How can I fix this problem?
The
Splitmethod returns an array, and you can’t resize an array.You can create a
List<string>from the array using theToListextension method:or the
List<T>constructor:Besides, you probably don’t want to use the
IList<T>interface as the type of the variable, but just use the actual type of the object:or:
This will let you use exactly what the class can do, not limited to the
IList<T>interface, and no methods that are not supported.