C# PROGRAMMING

What is Generics in C#

Generics allows you to define placeholders for fields, methods, parameters, etc. It replaces the placeholder with some specific type at compile time.

Sukhpinder Singh | .Net Developer
C# Programming
Published in
2 min readAug 5, 2020

--

Simple Generic In Action

Simple example of generic class

Below examples shows how to apply generics across class definition, variables, constructor, member functions & property.

As you can see below TestGenericClass is declared with “<T>” where <> defines its a generic class. The type of T will be defined later.

We can use any character instead of T.

How to use above class?

Here we will learn how to use the above generic class i.e. define type T inside the generic class.

Below an example of how we can use one generic class for different T types.

--

--

Sukhpinder Singh | .Net Developer
C# Programming

Programmer by heart | C# | .Net 6 | .Net 8 | dotnet | dotnetcore | Kubernetes | Angular | AWS | Remember to 👏 Linktree: https://linktr.ee/sukhpindersingh