re: Coding Concepts - Reflection VIEW POST

VIEW FULL DISCUSSION
 

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!

code of conduct - report abuse