Hi friends
can anybody Explain Advantages and disadvantages of using generics.
Loading
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 attend5days leftRegister
MuthuMari MRank #5,738 · 288 reputationPosted Apr 5, 2012, 8:53 PM EDT
Generics ,
Generic helps us to maximize the reuse of code, Type safety and better performance. Generics are most commonly used to create a collection. There are many new generic collection classes in the System.collection.Generics namespace. These classes are advised to be used for type safety and better performance over araylist.
We can also create our own Generic interface, classes, methods, events and delegates. Information on the types used in a generic data type may be obtained at run-time by means of reflection
Generics are a great way of writing classes that combine reusability, type safety and efficiency. Generics are commonly used with collections. .NET 2.0 has introduced a new namespace called System.Collections.Generic which contains classes that support generics.
The most common use for generic classes is with the collections like linked lists, hash tables, stacks, queues, trees and so on where operations such as adding and removing items from the collection are performed in more or less the same way regardless of the type of the data being stored.
Thanks.
Jignesh TrivediRank #16 · 50.3K reputationPosted Apr 5, 2012, 8:57 PM EDT
Generics are a new feature in version 2.0 of the C# language and the common language runtime (CLR). Generics introduce to the .NET Framework the concept of type parameters, which make it possible to design classes and methods that defer the specification of one or more types until the class or method is declared and instantiated by client code.
A primary reason is the type safety at compile time. If you are passing two Type objects you are placing the responsibility at the developer instead of the compiler.
Another reason to use a generic is if you want to apply constraints to the type
Please refer,
http://msdn.microsoft.com/en-us/library/ms172194.aspx
VulpesRank #55 · 29.2K reputationPosted Apr 6, 2012, 2:02 AM EDT
SenthilkumarRank #387 · 6.5K reputationPosted Apr 6, 2012, 11:16 PM EDT
Advantages of Generics:
More info:
http://msdn.microsoft.com/en-us/library/ms172194(v=vs.85).aspx
http://venkatcsharpinterview.blogspot.in/2011/05/advantages-and-disadvantages-of-using.html