Generics are useful for writing code that is reusable across different types of variables and classes. They also help programmers avoid errors such as the following:
- int x = 3;
- // error: cannot implicitly convert type 'int' to 'double'
- double y = x; // error: cannot implicitly convert type 'double' to 'int'
- In C sharp, generics can be used with both primitive data types and reference data types.
Share a personalized message with your friends.