Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


Enhance the type safety of your code and easily create applications using .Net Generics 4.0

  • Learn how to use Generics’ methods and generic collections to solve complicated problems.

  • Develop real-world applications using Generics

  • Know the importance of each generic collection and Generic class and use them as per your requirements

  • Benchmark the performance of all Generic collections

In Detail

Generics were added as part of .NET Framework 2.0 in November 2005. Although similar to generics in Java, .NET generics do not apply type erasure but every object has unique representation at run-time. There is no performance hit from runtime casts and boxing conversions, which are normally expensive..NET offers type-safe versions of every classical data structure and some hybrid ones.

This book will show you everything you need to start writing type-safe applications using generic data structures available in Generics API. You will also see how you can use several collections for each task you perform. This book is full of practical examples, interesting applications, and comparisons between Generics and more traditional approaches. Finally, each container is bench marked on the basis of performance for a given task, so you know which one to use and when.

This book first covers the fundamental concepts such as type safety, Generic Methods, and Generic Containers. As the book progresses, you will learn how to join several generic containers to achieve your goals and query them efficiently using Linq. There are short exercises in every chapter to boost your knowledge.

The book also teaches you some best practices, and several patterns that are commonly available in generic code.

Some important generic algorithm definitions are present in Power Collection (an API created by Wintellect Inc.) that are missing from .NET framework. This book shows you how to use such algorithms seamlessly with other generic containers.

The book also discusses C5 collections. Java Programmers will find themselves at home with this API. This is the closest to JCF. Some very interesting problems are solved using generic containers from .NET framework, C5, and PowerCollection Algorithms – a clone of Google Set and Gender Genie for example!

Subscriber Reviews

Average Rating: 5 out of 5 rating Based on 1 Rating

"I've used Generics, now I understand them." - by Relathor on 21-AUG-2012
Reviewer Rating: 1 star rating2 star rating3 star rating4 star rating5 star rating
As the title says, I had used Generics, mainly because I figured that I should use tools that already exist rather than reinvent the wheel. That being said, I didn't really understand them all that well or all the advantages.

My understanding benefitted greatly from this book, but surprisingly not just in the area of Generics but from other areas as well (the LINQ chapter is great).

Report as Inappropriate

Table of Contents



The publisher has provided additional content related to this title.


Downloading the example code for this book

  • You can download the example code files for all Packt books you have purchased from your account at
  • If you purchased this book elsewhere, you can visit and register to have the files e-mailed directly to you.