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