Skip to main content

Posts

Showing posts with the label Generics

C# Advanced Topics - Generics

Generics  Before we start learning What Generics is ?  , let me explain what problem generics came to solve . In .NET version 1 , we don't have generics .So ,lets say we need to create a list to store a list of numbers . The implementation of that class looks like below :  Currently , as I am not concentrating on how data structures works , just assumed a sample list class with  only Add method , which add the passed integer into its list. Rather than defining all the methods like Remove , find and properties and functionality and so on , just planned to have my class and projected on how generics came into existence . Let me define a simple class object here :  Now , if i plan to store a book to the list defined above it doesn't work as int is a value type and our book class will be a reference type . So , I am forced to create some class like below, which will give the ability to add a list of books :  So , th...