Tuesday, September 19, 2006

.NET : Generics

@ Why use Generics?
Develpers used the Object class for parameters and members, and would cast other classes to and from the Object class.
1. Using generics allows the comipler to catch type errors before your program runs, namely, its' type-safe.
2. Using generics doesn't require casting or boxing, which improves run-time performance.

@ .NET built-in generic types inludes:
1. Nullable
2. EventHandler
3. System.Collection.Generic, including Dictionary, Queue, SortedDictionary, and SortedList.

^ Generic应该就是被看成是一个语言特性。它诞生了,成为了一种语言的feature,目的是用来解决从前的写法的问题。所以,就应该完全抛弃掉从前的写法,使用Generic这个语言特性。无论是Collection还是自己写的东西。对我个人来说,以后所有的程序都将全盘使用Generic这种思想和特性,消除type-safe问题,也让程序更简洁漂亮一些。