Generics
A generic collection is strongly typed (type safe), meaning that you can only put one type of object into it . As we know different collection in C# like Array, ArrayList,HashTable etc.
Array
Array is strong type because there is no boxing and unboxing. It's performance is better than other collection.But there is a weak point is that it is a fixed length.
Array is strong type because there is no boxing and unboxing. It's performance is better than other collection.But there is a weak point is that it is a fixed length.
And ArrayList and HashTable is resizable but weak point is that it takes only objects and then It has more boxing and unboxing.
After reading above both line software developers think that, we have read any thing there is some lackness in very topic or every where.
I think one question is arrising in software developers mind that, if C# provide any other collection which fulfill both above lackness.
Now software developers want to take advantage of both then one picture comes in mind That is Generic Collection. Generic collection help us to create strong, flexible type collection easy.
I think one question is arrising in software developers mind that, if C# provide any other collection which fulfill both above lackness.
Now software developers want to take advantage of both then one picture comes in mind That is Generic Collection. Generic collection help us to create strong, flexible type collection easy.
First we are talking about Generics then Generic Collection.
Generics are the most power features in C# 2.0 .
Generics allow you to define type-safe classes without compromising type safty, performance or productivity. Generic introduce to the .NET Framework the concept of type parameter, which make it possible to design classes and methods.
Generics allow you to define type-safe classes without compromising type safty, performance or productivity. Generic introduce to the .NET Framework the concept of type parameter, which make it possible to design classes and methods.
Example
I want to compare two values first I will do it with simple class after that we will do it by using Generic .
I want to compare two values first I will do it with simple class after that we will do it by using Generic .
Let’s try to understand by a practical example.
Open Visual Studio.
Click on Project and set the name Application is MyFirstGenericApplication
Now try to use first method means simple class
Add a Check Class
- public class Check
- {
- public bool Compare(int a, int b)
- {
- if (a == b)
- {
- return true;
- }
- else
- {
- return false;
- }
- }
- }


Join the conversation! Your thoughts help the community grow.