Chapter 9 C # Generics

This article is transferred from: http://m.biancheng.net/csharp/90/

Generics is a new syntax introduced by C # 2.0, not syntactic sugar, but 2.0 features provided by the framework upgrade.

When we are programming programs, we often encounter modules with very similar functions, except that they process different data.

But we have no choice but to write multiple methods to deal with different data types.

At this time, then the question is coming, is there a way to use the same method to handle the method of passing in different types of parameters? The emergence of generics is specifically to solve this problem.

Generics are in the System.Collections.Generic namespace and are used to constrain parameter types in classes or methods.

Generics are widely used, including methods, classes, and collections.

In this chapter:
1.  Introduction to C # Generics
2.  C # nullable type: Nullable
3.  Definition and use of C # generic methods
4.  Definition and use of C # generic classes
5.  C # generic collection definition and use
6.  C # IComparable, IComparer interface: compare the values ​​of two objects

Guess you like

Origin www.cnblogs.com/hanguoshun/p/12729410.html