Basic Type-generic (2)

Source: Internet
Author: User
16.4 generic interface

16.5 generic delegation

16.6 generic Method
Public sealed class program {
Public static void Swap <T> (ref T a, ref T B ){
T temp;
Temp =;
A = B;
B = temp;
}
Public static void CallingSwap (){
Int32 n1 = 10, n2 = 20;
Console. WriteLine ("n1 = {0}, n2 = {1}", n1, n2 );
Swap <Int32> (ref n1, ref n2 );
Console. WriteLine ("n1 = {0}, n2 = {1}", n1, n2 );
String s1 = "Hello", s2 = "World ";
Console. WriteLine ("s1 = {0}, s2 = {1}", s1, s2 );
Swap <String> (ref s1, ref s2 );
Console. WriteLine ("s1 = {0}, s2 = {1}", s1, s2 );
Console. ReadLine ();
}
Public static void Main (){
CallingSwap ();
}
}

16.7 generic and other members
In C #, attribute, indexer, event, operator method, constructor, and summarizer cannot have type parameters. However, they can be defined in a generic type, and the code in these members can use type parameters.
16.8 verifiable and restricted



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.