.NET 4.0 Generics Beginner's Guide

More Information
  • How different kinds of generic listsare related
  • How to implement your own generic list
  • Query every kind of generic container alike with Linq Standard Query Operators
  • Augment .NET collections with general purpose algorithms available in C5 and PowerCollection
  • Build concurrent apps in breathing easy steps.
  • Find those algorithms you have been missing in .NET framework in PowerCollection and C5 API.
  • Learn how different generic collections/containers perform under benchmarking, and when to use one over another
  • Port your STL code blocks to .NET Generics which can be very handy if you are a veteran C++ developer and looking for an alternative in .NET world.

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!

  • 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
Page Count 396
Course Length 11 hours 52 minutes
ISBN 9781849690782
Date Of Publication 26 Jan 2012
Why bother learning about generic lists?
Types of generic lists
Checking whether a sequence is a palindrome or not
Time for action — creating the generic stack as the buffer
Time for action — completing the rest of the method
Designing a generic anagram finder
Time for action — creating the method
Life is full of priorities, let's bring some order there
Time for action — creating the data structure for the prioritized shopping list
Time for action — let's add some gadgets to the list and see them
Time for action — let's strike off the gadgets with top-most priority after we have bought them
Time for action — let's create an appointment list
Live sorting and statistics for online bidding
Time for action — let's create a custom class for live sorting
Why did we have three LinkedList as part of the data structure?
An attempt to answer questions asked by your boss
Time for action — associating products with live sorted bid amounts
Time for action — finding common values across different bidding amount lists
You will win every scrabble game from now on
Time for action — creating the method to find the character histogram of a word
Time for action — checking whether a word can be formed
Time for action — let's see whether it works
Trying to fix an appointment with a doctor?
Time for action — creating a set of dates of the doctors' availability
Time for action — finding out when both doctors shall be present
Revisiting the anagram problem
Time for action — re-creating the anagram finder
Lists under the hood
What makes LINQ?
Time for action — creating an Extension method
Time for action — consuming our new Extension method
Putting it all together, LINQ Standard Query Operators
Time for action — getting the LINQPad
Time for action — finding all names with *am*
Time for action — finding all vowels
Time for action — finding all running processes matching a Regex
Time for action — playing with the indexed version of Where()
Time for action — learn how to go about creating a Where() clause
Time for action — let's say "Hello" to your buddies
Time for action — radio "Lucky Caller" announcement
Time for action — flattening a dictionary
Time for action — leaving the first few elements
Time for action — picking conditionally
Time for action — skipping save looping
Time for action — reversing word-by-word
Time for action — checking whether a given string is a palindrome or not
Time for action — sorting names alphabetically
Time for action — sorting 2D points by their co-ordinates
Time for action — sorting a list of fruits
Time for action — indexing an array of strings
Time for action — grouping by length
Time for action — finding common names from two names' lists
Time for action — finding all names from the list, removing duplicates
Time for action — pulling it all together including duplicates
Time for action — finding all names that appear mutually exclusively
Time for action — removing duplicate song IDs from the list
Time for action — making sure it works!
Time for action — making a list out of IEnumerable
Time for action — tagging names
Time for action — one-to-many mapping
Time for action — finding the first element that satisfies a condition
Time for action — getting acquainted with FirstOrDefault()
Time for action — checking whether a sequence is palindromic
Time for action — understanding ElementAt()
Time for action — check out DefaultIfEmpty()
Time for action — generating arithmetic progression ranges
Time for action — running a filter on a range
Time for action — let's go round and round with Repeat()
Time for action — checking whether there is only one item matching this pattern
Time for action — set to default if there is more than one matching elements
Time for action — checking Any()
Time for action — how to check whether all items match a condition


Sudipta Mukherjee

Sudipta Mukherjee was born in Kolkata and migrated to Bangalore. He is an electronics engineer by education and a computer engineer/scientist by profession and passion. He graduated in 2004 with a degree in electronics and communication engineering.

He has a keen interest in data structure, algorithms, text processing, natural language processing tools development, programming languages, and machine learning at large. His first book on Data Structure using C has been received quite well. Parts of the book can be read on Google Books. The book was also translated into simplified Chinese, available from Amazon.cn. This is Sudipta's second book with Packt Publishing. His first book, .NET 4.0 Generics , was also received very well. During the last few years, he has been hooked to the functional programming style. His book on functional programming, Thinking in LINQ, was released in 2014. He lives in Bangalore with his wife and son.

Sudipta can be reached via e-mail at sudipto80@yahoo.com and via Twitter at @samthecoder.