using System.Reflection; class MyClass { public int MyMethod(int a, int b) { return a + b; } } class Program { static void Main() { MethodInfo method = typeof(MyClass).GetMethod("MyMethod"); Console.WriteLine(method.Name); } }
using System.Reflection; class MyClass { public int MyMethod(int a, int b) { return a + b; } public void MyOtherMethod() {} } class Program { static void Main() { Type t = typeof(MyClass); foreach(MethodInfo method in t.GetMethods()) { Console.WriteLine(method.Name); } } }In this example, we use the Type.GetMethods() method to get an array of all the MethodInfo objects for the methods in the MyClass class. We then loop through this array and print the names of each method to the console. This example also belongs to the System.Reflection package library.