// We can then Create a new Instance of whatever this type may be, and call it's methods.
object integerInstance = Activator.CreateInstance(integerTypeAssembly);
// Now we can use integerInstance as if it was an Intger Type, calling its MaxCValue function.
System.Console.WriteLine(integerInstance.MaxValue());
You're very much correct, I should of tested the snippet in .Net Fiddle before posting it. I wrote is as pseudo code, but can see how it could be misinterpreted. I've updated the example with one that actually works. Although the Integer class is a very boring example!
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
2nd code example doesn't work
// Using Reflection to get information from an Assembly:
System.Reflection.Assembly integerTypeAssembly = typeof(System.Int32).Assembly;
System.Console.WriteLine(integerTypeAssembly); // mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
// We can then Create a new Instance of whatever this type may be, and call it's methods.
object integerInstance = Activator.CreateInstance(integerTypeAssembly);
// Now we can use integerInstance as if it was an Intger Type, calling its MaxCValue function.
System.Console.WriteLine(integerInstance.MaxValue());
Hey Usman,
You're very much correct, I should of tested the snippet in .Net Fiddle before posting it. I wrote is as pseudo code, but can see how it could be misinterpreted. I've updated the example with one that actually works. Although the Integer class is a very boring example!