Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Non Generic object based class
//Title of this code //Rextester.Program.Main is the entry point for your code. Don't change it. //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 using System; using System.Collections.Generic; using System.Linq; using System.Text.RegularExpressions; namespace Rextester { class NonGen { object ob; // ob is now of type object // Pass the constructor a reference of type object. public NonGen(object o) { ob = o; } // Return type object. public object GetOb() { return ob; } // Show type of ob. public void ShowType() { Console.WriteLine("Type of ob is " + this.GetOb().GetType().Name.ToString()); } } public class Program { public static void Main(string[] args) { NonGen iOb; var v=0; //Type t=typeof( // 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. 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"); iOb=strOb; // 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! } } }
run
|
edit
|
history
|
help
0
sitjreoit
Validate or get the check digit of a segment of a Windows 8 / 10 activation installation ID
Sam a,b and c
MVC Learning
Contraseña final
Pizzas & List of Tuples
Padma. C#
SKR2
852
Found many section of times intersect (can edit)