Some
reading is required here.
Generally they help in type checking. i.e Using generics allows the compiler to help you check the correctness of your code by inferring information from the specified types. They also make your programming easier by not having to put a lot of casts. e.g
if you do
- ArrayList a = new ArrayList();
-
a.Add("test");
You
cannot do
even if you know that the object there is a string.
You have to use
With generics that is not required, you simply do
- List<string> a = new List();
-
a.Add("test");
-
string s = a[0];
From now on the compiler will be helping you by inserting the casts where required and also stopping you from putting non-strings in that List.