.NET Generics

Allow for:

  • generalization of logic based on available types
  • specify possible supported types
  • re-usability of code
  • type safety
  • defers the exact specification of logic until the class or method is declared and instantiated by user code with all type parameters specified
  • mostly used for collections (some non-generic versions of collection are not recommended like ArrayList i.e.)
  • information of exact type parameters used in a generic can be obtained at runtime by reflection

Further read:

https://learn.microsoft.com/en-us/dotnet/standard/generics/

Leave a Reply

Your email address will not be published. Required fields are marked *

Solve : *
1 + 6 =