static void Main() { NonGen iOb; // Create NonGen object. iOb = new NonGen(102); // Show the type of data stored in iOb. iOb.ShowType(); // Get the value in iOb. // This time, a cast is necessary. int v = (int)iOb.GetOb(); Console.WriteLine("value: " + v); Console.WriteLine(); // Create another NonGen object and store a string in it. NonGen strOb = new NonGen("Non-Generics Test"); // Show the type of data stored in strOb. strOb.ShowType(); // Get the value of strOb. // Again, notice that a cast is necessary. String str = (string)strOb.GetOb(); Console.WriteLine("value: " + str); // This compiles, but is conceptually wrong! iOb = strOb; // The following line results in a runtime exception. // v = (int) iOb.GetOb(); // runtime error! }
public static int Main() { GenStruct <object> gso = new GenStruct <object> (); GenStruct <string> gss = new GenStruct <string> (); if (gso.inc(1) != 2) { return(1); } if (gss.inc(2) != 3) { return(1); } if (gso.newArr().GetType() != typeof(object [])) { return(1); } if (gss.newArr().GetType() != typeof(string [])) { return(1); } Gen <string> g = new Gen <string> (); testInterface(g); NonGen ng = new NonGen(); testInterface(ng); Bla bla = new Bla(); string [] arr = { "a", "b", "c" }; if (!bla.work(arr)) { return(1); } return(0); }
public static void Main() { NonGen iOb = new NonGen(102); iOb.showType(); int v = (int)iOb.getob(); Console.WriteLine("value: " + v); Console.WriteLine(); NonGen strOb = new NonGen("Non-Generics Test"); strOb.showType(); String str = (string)strOb.getob(); Console.WriteLine("value: " + str); }