Use. Net generic to implement tuple

Source: Internet
Author: User
Although the DOTNET model has very weak functions, it is good to implement tuple, because DOTNET makes different types for reference of different models of classes with the same name. therefore, tuple <t1> and tuple <t1, T2> are different classes. with this rule, you can easily implement a tuple (C ++ template is complicated)

Public class tuple <t1>
{
T1 _ T1;
Public tuple (T1 T1)
{
This. _ T1 = T1;
}
Public T1 item_1
{
Get {return this. _ T1 ;}
}
};
Public class tuple <T1, T2>: tuple <t1>
{
T2 _ T2;
Public tuple (T1 T1, T2 T2): Base (T1)
{
This. _ t2 = t2;
}
Public T2 item_2
{
Get {return this. _ T2 ;}
}
};
Public class tuple <T1, T2, T3>: tuple <T1, T2>
{
T3 _ T3;
Public tuple (T1 T1, T2 T2, T3 T3): Base (T1, T2)
{
This. _ T3 = T3;
}
Public T3 item_3
{
Get {return this. _ T3 ;}
}
};

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.