Get invaluable Interview and Career Tips delivered directly to your inbox. Get your news alert set up today, Once you confirm your Email subscription, you will be able to download Job Inteview Questions Ebook . Please contact me if you there is any issue with the download.
Delegates and Generics in c#
Profile Answers by mfrony Questions by mfrony
Questions by mfrony
Editorial / Best Answer
sutanu_halderProfile Answers by sutanu_halder Questions by sutanu_halder
Advantage of Generic:-
1. Generics provide type safety without the overhead of multiple implementations.
Ex. We can create a linked list of string.
LinkedList<string>linkList=new LinkedList<string>();
There is no need to inherit from a base type and override members.The linked list is ready
for immediate use.
2. There is no need to write code to test for the correct data type because it is enforced
at compile time. The need for type casting and the possibility of run-time errors are
reduced.
3. Generic collection types generally perform better for storing and manipulating value
types because there is no need to box the value types.
4. Generic delegates enable type-safe callbacks without the need to create multiple delegate
classes.
5.Generic delegates can also be used in dynamically generated code without requiring the
generation of a delegate type. This increases the number of scenarios in which you can use
lightweight dynamic methods instead of generating entire assemblies.
Advantage of Delegate:
Delegates are managed function pointers. they are type checked and held in spaces that can
be reclaimed by the memory manager.
Related Answered Questions