In 2.0, Generics were added. If you haven’t played with generics before, they are a way of declaring a type for an object for the compiler, such as a list, without having to use the System.Object class. In this way, you can have strongly typed lists instead of a list of objects that you must then typecast when you pull them back out.
If you think of generics outside the programming world, you might think of generic medicine. It is medicine that has the same effects as the name brand stuff, but isn’t attached to any brand. Generics in programming are like this. They aren’t bound to a type, but share the same methods and classes.
Here are a few examples of the List object from System.Collections.Generics. The list is exactly as it says. You add items to the list that are the same type as you delcare, and then access them using a zero-based index. It’s similar to the ArrayList from System.Collections, but the return type of the items is not System.Object that must be typecast.
Read more »
November 27, 2007
Posted by
Broken Bokken |
.Net |
ASP.NET, C#, .Net, Programming, .Net 2.0, System.Collections.Generic, Generic Return, Return Type, IConvertible, TypeCast, typeof, ChangeType, Convert, Generics, .Net Dojo, Technology |
2 Comments