Skip to main content

Professional .NET 2.0 Generics

Professional .NET 2.0 Generics

Tod Golding

ISBN: 978-0-471-75769-6

Oct 2005

386 pages

Select type: E-Book

$25.99

Description

The power and elegance of generic types have long been acknowledged. Generics allow developers to parameterize data types much like you would parameterize a method. This brings a new dimension of reusability to your types without compromising expressiveness, type-safety, or efficiency. Now .NET generics makes this power available to all .NET developers. By introducing generic concepts directly into the Common Language Runtime (CLR), Microsoft has also created the first language-independent generics implementation. The result is a solution that allows generic types to be leveraged by all the languages of the .NET platform.

This book explores all aspects of the .NET generics implementation, covering everything from fundamental generic concepts, to the elements of generic syntax, to a broader view of how and when you might apply generics. It digs into the details associated with creating and consuming your own generic classes, structures, methods, delegates, and interfaces, examining all the nuances associated with leveraging each of these language constructs. The book also looks at guidelines for working with generic types, the performance gains achieved with generics, the new generic container libraries (BCL and third party), and key aspects of the underlying .NET implementation.

For those transitioning from C++, the book provides an in-depth look at the similarities and differences between templates and.NET generics. It also explores the syntactic variations associated with using generics with each of the .NET languages, including C#, Visual Basic, J#, and C++.

Acknowledgments.

Introduction.

Chapter 1: Generics 101.

Chapter 2: Valuing Type Safety.

Chapter 3: Generics ≠ Templates.

Chapter 4: Generic Classes.

Chapter 5: Generic Methods.

Chapter 6: Generic Delegates.

Chapter 7: Generic Constraints.

Chapter 8: BCL Generics.

Chapter 9: Reflection, Serialization, and Remoting.

Chapter 10: Generics Guidelines.

Chapter 11: Under the Hood.

Chapter 12: Using Generics with C++.

Chapter 13: Using Generics with J#.

Chapter 14: Power Collections.

Index.

Code Downloads
Code downloads for this title are available here.
Download
ChapterPageDetailsDatePrint Run
5Error in Code
first block of code, line below the C# heading:

SalesPerson aSalesPerson = (SalesPerson)child[0].Data;

should be:

SalesPerson aSalesPerson = (SalesPerson)child1[0].Data;
07/11/2007

225Error in Text
There is no need for explicit casting in the line below:
Object[] orders = (Object[])cust.Items;

should be:
Object[] orders = cust.Items
09/23/08

31Error in Code
2nd and 4th shaded code blocks, under each [C# code] heading:
1st line of each:
Interace

should be:
interface
5/30/06

31Error in Code
2nd and 4th shaded code blocks, under each [C# code] heading:
2nd line of each, in Public:
P

should be:
p
5/30/06

51Error in Code
code block, VB code, 5th line:

False

should be:

True
07/11/2007

58Error in Code
In the VB Code example (top shaded code block), 4th line from end:
Dim cache2 As New MyCache(Of String, String)()

should be:
Dim cache2 As New MyCache(Of String, Integer)()
1/11/06

102Error in Code
2nd and 4th lines of shaded code on the page (both C# lines):
the ending section of both lines in parens:
(Byval val As Order)

should be:
(Order val)
7/26/06

116Error in Code
Page 116, 2nd shaded code section (C#), lines 9 and 10

Code reads:

public bool Update() {
return false;

Should be:

public void Update() {
07//31/06