Net-informations.com
SiteMap  | About    

What are generics in c#

Generics refers to the technique of writing the code for a class without specifying the data type(s) that the class works on. It allow you to define type-safe data structures, without committing to actual data types. It allows writing less but more effective code and provides flexibility and power but the developer needs to be responsible while using it.

A generic class can be defined using angle brackets < >.

Example

Or

You specify the data type when you declare an instance of a generic class . This allows a generic class to be specialized for many different data types while only having to write the class once. This results in a significant performance boost and higher quality code, because you get to reuse data processing algorithms without duplicating type-specific code. As a result of generics being used the compiler can perform compile-time checks on code for type safety. Also generics are faster than using objects as it either avoids boxing/unboxing (where .net has to convert value types to reference types or vice-versa) or casting from objects to the required reference type.

Sell also..... C# List









net-informations.com (C) 2017    Founded by raps mk
All Rights Reserved. All other trademarks are property of their respective owners.