C # type Parameters Study

Source: Internet
Author: User
Type Parameters

A class definition may specify a set of type parameters by following the class name with Angle brackets enclosing a list of type parameter names. the type parameters can the be used in the body of the class declarations to define the members of the class. in the following example, the type parameters of pair are tfirst and tsecond:

Public class pair <tfirst, tsecond>
{
Public tfirst first;

Public tsecond second;
}

A class type that is declared to take type parameters is called a generic class type. struct, interface and delegate types can also be generic.

When the generic class is used, type arguments must be provided for each of the type parameters:

Pair <int, string> pair = new pair <int, string> {First = 1, second = "two "};
Int I = pair. First; // tfirst is int
String S = pair. Second; // tsecond is string

A generic type with type arguments provided, like pair <int, string> abve, is called a constructed type

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.