Run Code
|
API
|
Code Wall
|
Misc
|
Feedback
|
Login
|
Theme
|
Privacy
|
Patreon
Symantic check for object type variables
//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(); iOb.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! int t=(int)iOb.GetOb(); // The following line results in a runtime exception. // v = (int) iOb.GetOb(); // runtime error! } } }
run
|
edit
|
history
|
help
0
Дамир
Determine if Two Words Are Anagrams of Each Other
find maximum consecutive repeating character
Numeric to graphical output using string extension method
Ty
งานสอบ
Recomment toTheGit(TestArray)
Round Program
Just tries to add/remove items to the list
Gradebook