What is a generic class in C#

The concept of generics can be found both in C# and Java. In C++ this same concept is called Templates. This feature provided to you by these languages gives you the power to write a set of functionality in such a manner that it can operate on any data type you want.

Let’s take an example of a stack

If you have read the course on Data Structure during your college days then you might very well know what a stack is and how to create a stack using C or C++. Most of us learn to create a Stack using an array and a variable to point to the top of the stack. Also most of us learn how to create a stack which can be used to store integer values. You can push integer values on the stack and also pop out integer values. To create such a stack you use an array of integers.
Now let’s say if I ask you to create such a Stack which can store any type of data in it. I should be able to use this stack for storing integers or floats or characters or any other user defined data type. Scratch your head and think if you can create such a stack using C ! The answer will be no. This is because languages like C does not have the concept of generics. But you can achieve this by using C# or Java or C++ because they support the concept of generics.

So how do we define generics?

Technically speaking generics is a feature in C# using which you can create a class or a function so that they can accept any type of data and perform the logic on it.

Quick Links



Total Followers
Study Group Created
Study Group Joined
Following Teacher
Following Organization
Blog Articles Added
Questions Asked
Questions Answered
Jobs Posted
Total Members in Group
Questions asked by members
Tasks added in this Group

Please wait..


Login to Open ESchool OR Create your account    Login   SignUp