Demystifying C# Generics

AramT
88.7K views

Open Source Your Knowledge, Become a Contributor

Technology knowledge has to be shared and made accessible for free. Join the movement.

Create Content

In .Net framework the collections namespace includes classes that represent collection of objects that include lists, queues, bit arrays, hash tables and dictionaries.

The namespace System.Collections.Generic is the generic version of System.Collection namespace. Using it, you can define strongly typed collections while gaining all benefits of generics (code reusability, type safety and better performance).

Let’s take the most commonly used Collection type which is the List. I will not be explaining about Collections now because it is outside the scope of this article.

So with generics, the List will have its parameter T, that you can pass to it whatever type you like and you will have a list of that type.

Check the below example, we are defining a list of floating points of type `float`
Open Source Your Knowledge: become a Contributor and help others learn. Create New Content