Posts

Showing posts with the label Generics

What is Generics?

Generics  are classes, structures, interfaces, and methods that have placeholders (type parameters) for one or more of the types that they store or use. A generic collection class might use a type parameter as a placeholder for the type of objects that it stores; the type parameters appear as the types of its fields and the parameter types of its methods. A generic method might use its type parameter as the type of its return value or as the type of one of its formal parameters public class Generic {     public T Field; } public static void Main() {     Generic  g = new 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 speci...