That's right.
A regular collection, such as an ArrayList, implicitly stores objects.
This means that it is:
ArrayList list = new ArrayList(); list.Add(5); list.Add("FooBar");
It is a legal code. This causes several problems.
- Usually you do not want to store different types in the same collection, and checking compile time is good for this.
- When you store a value type (for example, the integer 5 above), it must be placed in the reference type before it can be stored in the collection.
- When reading a value, you must drop it back from Object to the desired type.
However, you fix all these problems using a common collection:
List<int> list = new List(); list.Add(5);
You also get intellisense support when working directly with collection indexes, and not just with the common intellisense "object".
Flyswat
source share