Dot Net Perls
Top 37 C# Example Pages...

["*rywsyt.c(CEST~~}T~~Y6696FXB.BBCE/CS}T~~}T~~","GetMethod"," references methods with only a string name. With it we call a method whose name equals this string. This involves the System.Reflection namespace and the MethodInfo type found there.","Example."," Before we begin, please notice the System.Reflection namespace. Reflection here refers to how C# programs can look inside themselves and then act upon their metadata programmatically. ","Next: ","We want to call the Inform static method by using the string \"Inform\" and we want to call it twice with different parameters.","Static Method ","static","ins","class","adsbygoogle","data-ad-client","ca-pub-4712093147740724","data-ad-slot","6227126509","data-ad-format","auto","ins","class","adsbygoogle","data-ad-client","ca-pub-4712093147740724","data-ad-slot","6227126509","data-ad-format","auto","C# program that uses GetMethod","\n\nusing System;\nusing System.Reflection;\n\nstatic class Methods\n{\n public static void Inform(string parameter)\n {\n Console.WriteLine(\"Inform:parameter={0}\", parameter);\n }\n}\n\nclass Program\n{\n static void Main()\n {","\n // Name of the method we want to call.\n ","string name = \"Inform\";","\n\n // Call it with each of these parameters.\n ","string[] parameters = { \"Sam\", \"Perls\" };","\n\n // Get MethodInfo.\n ","Type type = typeof(Methods);\n MethodInfo info = type.","GetMethod","(name);","\n\n // Loop over parameters.\n ","foreach (string parameter in parameters)\n {\n info.Invoke(null, new object[] { parameter });\n }\n }\n}\n\n","Output","\n\nInform:parameter=Sam\nInform:parameter=Perls","In this example,"," the expression typeof(Methods) references the Methods class and returns Type pointer. We next call the instance method GetMethod on the type instance. This returns a MethodInfo instance or null if no method was located. ","Type ","type","Next,"," in the foreach loop, we repeatedly call Invoke. The first argument to Invoke is null. This is because the target method is static and has no instance expression. The second argument is wrapped in an object array. ","Foreach ","foreach","Object Array ","object-array","Note: ","You must do this even if there is only one required parameter. It is not optional.","MethodInfo Invoke ","methodinfo-invoke","Summary."," It is possible to call methods by their names in the C# language. Using reflection, you can create interesting abilities in your programs, such as query languages that can reference arbitrary methods in the metadata. ","Tip: ","This is best for situations where performance is not critical. It is ideal for less frequently used code.","ins","class","adsbygoogle","data-ad-client","ca-pub-4712093147740724","data-ad-slot","3679700504","data-ad-format","link","ins","class","adsbygoogle","data-ad-client","ca-pub-4712093147740724","data-ad-slot","6227126509","data-ad-format","auto","url(data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD/2wCEAAYEBAQFBAYFBQYJBgUGCQsIBgYICwwKCgsKCgwQDAwMDAwMEAwODxAPDgwTExQUExMcGxsbHB8fHx8fHx8fHx8BBwcHDQwNGBAQGBoVERUaHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fHx8fH//BABEIAK4A8AMAEQABEQECEQH/xABqAAEBAQEAAwEBAAAAAAAAAAAAAQIDBAUGBwgQAQABAgMCBgoMDAMJAAAAAAABAgMEERIFIQYTMUFRUhQVIjJxcoGRsbIHFiMzU1Rhc4KSodEIJDQ1NoSzwcPS4fBGdaIlQkNFYmN0o9P/2gAMAwAAAQACAAA/AP6pAAAAAAEAAAQDNQEAATMDMDMFzAzAzARVAAAAAFAAAAAAABAAEzVEzAAAABBBQAzAzAzQzMxVAzBQMxVQAAABXxnth2x8Y/0Ufyj4Ht1iuv8AZT9x7YdsfGP9FH8odusV1/sp+59BwfxuJxeCruYivXXxk08kRuimmeaIH0+xcVcvWpquTnOrLm6I6Hs8x7dAFEzEMwTNUMwMwBAAEBBDNQzEMwMwXNFMwXMURVABRVQAAfnY/LQH1XBX83XPnqvVpH2nBz3ifHn0Uvcq9+AgiAKiZiAPB23duW9l3q7dU0V9z3VMzEx3cRywPW7WuVU4aqaZyndyeGHyvbLaHxm79er70fGdnX+vX9aV7Z7R+M3fr1feHZ9/r1ec7Z7R+M3PrSL2wxHXq88r202j8ZufWkXtjiOvV530PB7EXr+CrrvVzcqi5Md1Oc5aaVfUbEv13LMzXMzOr90PZTKvcJmqGYLmKZoLmKoqoqoqgCqCoAPl54J4r4e35pHyHtbu9an7WZ4KY74W156hn2uXutT9r3Oxdn3sDha7N2qmqqq5NfcTMxlMRHPEK9/srBV4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