It reduce the code repetition ...............
Generic mean generalization of code, Writing generic code to reduce repetition of code.
To reduce the code repetition, generics is introduced where which has tendency to deal with any type of datatype which was defined during run-time.
Generics were added to version 2.0 of the C# language and the common language runtime (CLR). Generics introduce to the .NET Framework the concept of type parameters, which make it possible to design classes and methods that defer the specification of one or more types until the class or method is declared and instantiated by client code. For example, by using a generic type parameter T you can write a single class that other client code can use without incurring the cost or risk of runtime casts or boxing operations public class GenericList { void Add(T input) { } } class TestGenericList { private class ExampleClass { } static void Main() { // Declare a list of type int. GenericList list1 = new GenericList(); // Declare a list of type string. GenericList list2 = new GenericList(); // Declare a list of type ExampleClass. GenericList list3 = new GenericList(); } }
Generics were added to version 2.0 of the C# language and the common language runtime (CLR). Generics introduce to the .NET Framework the concept of type parameters, which make it possible to design classes and methods that defer the specification of one or more types until the class or method is declared and instantiated by client code. For example, by using a generic type parameter T you can write a single class that other client code can use without incurring the cost or risk of runtime casts or boxing operationspublic class GenericList {void Add(T input) { } } class TestGenericList {private class ExampleClass { }static void Main(){// Declare a list of type int.GenericList list1 = new GenericList();// Declare a list of type string.GenericList list2 = new GenericList();// Declare a list of type ExampleClass.GenericList list3 = new GenericList();} }
Generic type use to seprate the data type or it use to make collection as strong type.