using System; using System.Reflection; class ExampleClass { public int exampleInt; public string exampleString; public void exampleMethod() { } } class Program { static void Main(string[] args) { Type type = typeof(ExampleClass); MethodInfo[] methods = type.GetMethods(); foreach (var method in methods) { Console.WriteLine(method.Name); } } }
using System; using System.Reflection; interface ExampleInterface { int exampleInt { get; set; } void exampleMethod(); } class ExampleClass : ExampleInterface { public int exampleInt { get; set; } public void exampleMethod() { } } class Program { static void Main(string[] args) { Type type = typeof(ExampleInterface); MethodInfo[] methods = type.GetMethods(); foreach (var method in methods) { Console.WriteLine(method.Name); } } }In this example, we create an interface named ExampleInterface with a property and a method. We then create a class named ExampleClass that implements ExampleInterface and implements the property and method. We retrieve the type information for ExampleInterface using typeof() and retrieve all the methods using GetMethods(). We then use a foreach loop to print out the names of each method. Package/library: System.Reflection