Chapter 17 Quick Reference


Chapter 17 Quick Reference

To

Do this

Example

Instantiate an object by using a generic type.

Specify the appropriate type parameter.

Queue<int> myQueue =     new Queue<int>();

Create a new generic type.

Define the class by using a type parameter.

public class Tree<T> {     ... }

Restrict the type that can be substituted for the type parameter.

Specify a constraint by using a where clause when defining the class.

public class Tree<T> where T : IComparable<T> {     ... }

Define a generic method.

Define the method by using type parameters.

static Tree<T> BuildTree<T> (params T[] data) {     ... }

Invoke a generic method.

Provide types for each of the type parameters.

Tree<char> charTree =   BuildTree<char>('Z', 'X');




Microsoft Visual C# 2005 Step by Step
Microsoft® Visual C#® 2005 Step by Step (Step By Step (Microsoft))
ISBN: B002CKYPPM
EAN: N/A
Year: 2005
Pages: 183
Authors: John Sharp

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net