Problem solve Get help with specific problems with your technologies, process and projects.

Book Excerpt: .NET 2.0 Generics guidelines

Generics bring a heavy dose of flexibility to .NET 2.0. This chapter download provides more than 20 suggestions for best using the Generics class.

The Generics class introduced in .NET 2.0 gives developers the flexibility to write methods once and then let the .NET Framework take care of type issues. This class is a tremendous asset -- there is no boxing of objects or casting of exceptions, which improves performance, compile errors show up earlier in the coding process, and generics are implemented right into the Common Language Runtime.

Professional .NET 2.0 Generics by Tod Golding covers many aspects of this implementation, from methods and delegates to reflection, serialization and remoting. Golding provides code samples in both VB and C# and also includes chapters for using generics in C++ and J#.

Chapter 10, Generics Guidelines, provides what the author describes as an "evolving list" of guidelines for working with the Generics class in .NET 2.0. Golding offers nearly two dozen suggestions, from the use of generic collections and consistent Type Parameter names to using the least specialized interface in your APIs.

Golding emphasizes that the guidelines are not steadfast rules:

 

"Guidelines can and should be violated under certain circumstances. They exist purely to help you define the rules that should shape your general practices for deciding how and when to use a generic type. When you find exceptions to the rule, by all means—violate the rule. Just be sure that you can defend each violation and, if you can, you'll be fulfilling the spirit of what the guideline is trying to achieve."

Read the rest of the excerpt in this PDF.

MORE: Read Chapter 4, Generic Classes

 


Excerpted from the Wrox Press book,  Professional .NET 2.0 Generics (ISBN 0-7645-5988-5) by Tod Golding.
Copyright © 2005. Published by John Wiley & Sons Inc.. Reprinted with permission.

Dig Deeper on .NET Framework 2.0 and Visual Studio 2005 development

Start the conversation

Send me notifications when other members comment.

Please create a username to comment.

-ADS BY GOOGLE

SearchCloudComputing

SearchSoftwareQuality

TheServerSide.com

Close