Back to course

Introduction to Generics

C# Zero to Hero: Comprehensive Programming Masterclass

Generics

Generics allow you to write a class or method that can work with any data type, without losing type safety.

Example

csharp class MyGenericClass { public T data; }

MyGenericClass obj = new MyGenericClass(); obj.data = 10;

T is a placeholder for a type that will be specified later.