// NonGen // Gen, .
Using System;,
class NonGen {
object ob; // ob object
// object, public NonGen(object ) { ob = ;
}
// object, public object GetOb() {
Return ob;
}
// ob. public void ShowTypeO {
Console.WriteLine(" ob: " + ob.GetType());
}
}
// , class NonGenDemo { static void Main() {
NonGen iOb;
// NonGen. iOb = new NonGen(102);
// , iOb. iOb.ShowType();
// iOb.
// , int v = (int) iOb.GetObO;
Console.WriteLine(": " + v);
Console.WriteLine();
// NonGen // it.
NonGen strOb = new NonGen(" ");
// , strOb. strOb.ShowType();
// strOb.
// .
String str = (string) strOb.GetOb();
Console.WriteLine(": " + str);
// , ! iOb = strOb;
// // .
// v = (int) iOb.GetObO; // !
}
}
.
ob: System.Int32 : 102
ob: System.String :
, , .
. , , Non Gen. Non Gen , . . -, . -, . .
.
int v = (int) iOb.GetObO;
GetOb () object, , , GetOb (), v int. , . , int iOb. . , .
|
|
.
// , ! iOb = strOb;
// // .
// v = (int) iOb.GetObO; // !
strOb iOb. strOb , , . , NonGen , , NonGen NonGen. , . , GetOb (), int, int. , . , int. , , , . .
, . , , , , . ,
, . C# "" , , , .. , . . , . .
. , ob NonGen ShowType () .
Console.WriteLine(" ob: " + ob.GetType ());
11, object , . GetType (), , . , , ob, , , ob object. CLR .
. . TwoGen, Gen .
|
|
// V.
Using System;
class TwoGenCT, V> {
T obi;
V ob2;
// , // V. public TwoGen( ol, V 2) {
obi = ol; 2 = 2;
}
// V. public void showTypes() {
Console.WriteLine(" T " + typeof());
Console.WriteLine(" V " + typeof(V));
}
Return obi;
}
public V Get0bj2() { return ob2;
}
}
// , class SimpGen {
static void Main() {
TwoGenCint, string> tgObj =
new TwoGenCint, string>(119, " ");
// . tgObj.showTypes();
// , int v = tgObj.getobl();
Console.WriteLine(": " + v); string str = tgObj.GetObj2();
Console.WriteLine(": " + str);
}
}