Saturday, January 14, 2006

The New Generics

The VB.net has released a new namespace called generic which includes some of the classes that were supported by System.collection before such as (Array, Stack, Array List, Queue, Dictionary, etc ).

Now Generic types became more powerful and you will notice a large different between the performance of the updated Generic Classes. VB.NET 2005 supported a new methodology allow for the programmer to develop an Array collection doffed for a specific type rather than using the formal Object type as a default declaration.

A- Dim b as new Stack (of Integer)

B- Dim b as new Stack

In (A) we can notice that b has been declared to recognize only numbers that can be assigned to Integer. But in (b) it supports all the conversion from any type to the object type which takes a reference from the defined item and do a method called boxing upon the item. Any assigning in (A) cause an error assigning for the integer will cause the compiler to report an error. Furthermore the Typeof method make the processing for the collection faster regarding that it doesn't need to do the boxing task.

No comments: