define generics with example and advantages

Posted by Sheeba under ASP.NET on 11/3/2010 | Points: 10 | Views : 4852 | Status : [Member] | Replies : 1

define generics with example and advantages


Posted by: Lalji_mer on: 11/3/2010 [Member] Bronze | Points: 25

about generics you will get here

Generics main benefit is eliminating boxing and unboxing that is true, there are also other benefits like type safety, by using generics you eliminate type ambiguitiy.

1. Generics provide type safety without the overhead of multiple implementations. Ex. We can create a linked list of string. LinkedListlinkList=new LinkedList(); 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.


Sheeba, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response