GeekInterview.com
  I am new, Sign me up!
 
GeekInterview.com  >  Interview Questions  >  Microsoft  >  C#
Go To First  |  Previous Question  |  Next Question 
 C#  |  Question 418 of 436    Print  
delegates and Generics in c#
What is the advantage of using delegates and Generics in c# .


  
Total Answers and Comments: 3 Last Update: August 07, 2009     Asked by: mfrony 
  
 Sponsored Links

 
 Best Rated Answer

No best answer available. Please pick the good answer available or submit your answer.
April 18, 2008 05:35:46   #1  
sutanu_halder Member Since: December 2007   Contribution: 12    

RE: delegates and Generics in c#
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.

 
Is this answer useful? Yes | No
April 23, 2008 05:21:00   #2  
sutanu_halder Member Since: December 2007   Contribution: 12    

RE: delegates and Generics in c#
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.

 
Is this answer useful? Yes | No
August 07, 2009 07:52:40   #3  
chintan.desai Member Since: July 2009   Contribution: 8    

RE: delegates and Generics in c#
Adding on sutanu_halder answer:

1. Delegate executes asynchronousely while Generice execute synchronousely.
2. Delegate is not type safe. We can define anonymous method which can execute without creating delegate object in memory. Generic is type-safe.

 
Is this answer useful? Yes | No


 
Go To Top


 Sponsored Links

 
About Us -  Privacy Policy -  Terms and Conditions -  Contact -  Ask Question -  Propose Category -  Site Updates 

Copyright © 2005 - 2009 GeekInterview.com. All Rights Reserved

Page copy protected against web site content infringement by Copyscape