Generics in C#.Net

Generics allow us to create classes and methods in C#.Net that can work on different types of data.

For example – Consider the method that accepts the 2 integer arguments and returns the result of addition. But what if we want to add 2 floating point numbers? Do we need to create a separate method? The answer is No and this is when Generics come into picture.

With Generic method, we can write single method that can work on any data type say int, float, double or long.

You may also like...