Generic Class
What is generic class in C#?
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend4days leftRegister
VulpesRank #55 · 29.2K reputationPosted May 20, 2014, 12:55 PM EDT
For example System.Collections.Generic.Dictionary
var dict = new Dictionary
creates an instance of this class where the keys are strings and the values are ints.
In effect, K is replaced by string and V is replaced by int, wherever these parameters appear in the definition of the generic class and its members.
It is possible for type parameters to be subject to 'constraints'. For example, if a generic class is defined as follows:
class MyClass
{.....}
then T must be replaced with a type which implements IEnumerable, is a reference type and has a constructor which takes no parameters.
Munesh SharmaRank #174 · 13.9K reputationPosted May 20, 2014, 8:49 PM EDT
http://www.tutorialspoint.com/csharp/csharp_generics.htm