Wednesday, November 15, 2006

Good links to learn about Generics in .NET

The concept of Generics is old hat to seasoned .NET developers. While at the Connections conference last week, I attended Kathleen Dollard's session on it and was interested to learn more.

For those of you not familiar with it, Microsoft defines Generics as

"a feature in version 2.0 of .NET (not available in NET 1.1) and the
common language runtime (CLR). Generics introduce to the .NET Framework the
concept of type parameters, which make it possible to design classes and methods
that defer the specification of one or more types until the class or method is
declared and instantiated by client code
."

Sounds complicated, and it is, because Microsoft's explanation makes it so. Actually they are a lot easier to understand with the excellent series of articles by Charlie Calvert (here's Part I, Part II, Part III).

Charlie writes:

"Generics help developers write type safe code that is easy to reuse. They
help catch errors at compile time, rather than at run time. Generics make it
easier for developers to write code that is self descriptive. In particular,
they can help you avoid the confusing syntax and side effects involved in type
casting and boxing. When writing containers, they can also help you write one
class for use with many different types, rather than forcing you to write a new
class for each type that you want to handle."

There you have it. Don't use ArrayList in NET 2.0 as you used to in NET 1.1 Use generics instead.

See also:
Jesse Liberty (O'Reilly's Books) Intro to Generics

No comments:

Post a Comment