public class Generic
{public T Field;
}
public static void Main()
{Generic
g.Field = "A string";
Console.WriteLine("Generic.Field = \"{0}\"", g.Field);
Console.WriteLine("Generic.Field.GetType() = {0}", g.Field.GetType().FullName);
}
Generic classes encapsulate operations that are not specific to any particular data type. The most common use for generic classes is with the collections like linked lists, hash tables, stacks, queues, trees and so on where operations such as adding and removing items from the collection are performed in more or less the same way regardless of the type of the data being stored.
The advantage of generics is better type safety, code reusability and better performance.
Generics are most commonly used to create a collection