In: Computer Science
How does Generics and Parameterized classes promote reusability, give an example?
Introduction:
Generic category:
General in C # is its most powerful feature. Allows you to define secure data structures. This turns out to be amazingly powerful for working with high-level code because it helps to use algorithms for data processing without having to duplicate code of some kind.
Genetics are similar to templates in C ++ but are different in functionality and capacity. General introduces the concept of type parameters, due to the possibility of creating methods and classes that limit data type entries until the class or method is declared and entered by the client code. Parameter types are defined in standard class creation.
Benefits of Generics:
Uses for reuse: You can use one standard type definition for multiple purposes in the same code without any changes. For example, you can create a standard way to add two numbers. This method can be used to enter two numbers and two flats without code modification.
Security Type: Standard data types provide better type security, especially in the case of clusters. When using generics you need to define the type of objects to be passed to the collection. This helps the compiler to ensure that only those types of items specified in the description can be passed to the collection.
Functionality: Standard edition types provide better performance compared to standard program types because they reduce the need for box placement, non-boxing, and typing of variables or objects.
To make objects of a generic class, we use the following syntax.
// To create an object of generic class className <Type> obb = new className <Type>()
Type= Integer, String, etc

OUTPUT:
20
Your program
I hope this helps you. For any doubts feel free to ask in comments. Thank You.