Chapter 6: Generics
In the previous chapter, we learned about OOP in C#. In this chapter, we will explore the concept of generics. Generics allow us to create classes, structures, interfaces, methods, and delegates in such a manner that they will work in a type-safe environment with different data types. Generics were added as a part of the C# 2.0 release. It promotes code reusability and extensibility and is one of the most powerful features of C#.
We will learn about the following concepts in this chapter:
- Generic classes and generic inheritance
- Generic interfaces and variant generic interfaces
- Generic structures
- Generic methods
- Type constraints
By the end of this chapter, you will have gained the skills necessary to write generic types, methods, and variant generic interfaces and to use type constraints.