1 Code
1 usingSystem;2 usingSystem.Collections.Generic;3 usingSystem.Linq;4 usingSystem.Reflection;5 usingSystem.Text;6 usingSystem.Threading.Tasks;7 8 namespaceConsoleApplication19 {Ten class Program One { A Static voidMain (string[] args) - { - //The class in which the function is to be called is person theType TP =typeof(person); - - //the name of the method is: HelloWorld -MethodInfo method = TP. GetMethod ("Helloworldsuper"); + - //Create an example + Objectobj =activator.createinstance (TP); A at //calling Functions -Method. Invoke (obj,New Object[] {1,"2"}); - Console.readkey (); - } - } - in Public class Person - { to Public voidHelloWorld () + { -Console.WriteLine ("HelloWorld"); the } * Public voidHelloworldsuper (intAstringb) $ {Panax NotoginsengConsole.WriteLine ("HelloWorld HelloWorld"); - } the } +}
2 Show
C # console Activator and invoke, using reflection to invoke the parameter method of a class