This code:
int[] myArr = { 1, 2 };
myArr.Add(3);
throws on build:
error CS1061: "System.Array" does not contain a definition for "Add", and the extension method "Add", which takes the first argument of type "System.Array", was not found (do you miss the using directive or the assembly?)
The IList interface has an Add () method, but why doesn't the array implement it?
UPDATE: I see from the answers that he implements this explicitly, OK, I get this, thanks, I should better ask myself:
Why does the array really not provide Add (), OR, is it better why it should implement IList in the first place? Instead of implementing IList, it could be another interface (for example, IArray), which can ONLY be useful for members of the IList-eg array. IsFixedSize, IsReadOnly, IndexOf () ... just a thought
source
share