A brief description of generic types.

Source: Internet
Author: User

I have seen a lot of generic descriptions written by netizens, and many of them are illustrated by examples. It is a bit dizzy.
Later, I checked the video tutorial to understand the generic type.

The concepts of other generic types are not complex, but they are completed using real-time compilation.

A generic type is defined here.
Public class betterclass <t>
{
Private t obj1;

Public betterclass ()
{
}
}

For example, betterclass = new betterclass <string>;
When this sentence is compiled instantlyCodeWill build a new class in the memory.

Public class betterclass <string>
{
Private string obj1;

Public betterclass ()
{
}
}

For example, betterclass = new betterclass <int>;
When this code is compiled in real time, a new class will be built in the memory.

Public class betterclass <int>
{
Private string int;

Public betterclass ()
{
}
}

Note: The same type is only constructed once in the memory.

 TIt is just a 'placeholder '. during real-time compilation, it is replaced with the class instance specified during instantiation.

It's much easier to understand and learn other usage.

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.