C# Invoke Instance method of Type

CSharp · Console

/Program.cs

using System;
					
public class Program
{
	public static void Main()
	{
		var theString = "hello";
		var method = theString.GetType().GetMethod(
			"Substring",
			new[] {typeof(int), typeof(int)}); //The types of the method arguments
		var result = method.Invoke(theString, new object[] {0, 4});
		Console.WriteLine(result); //"hell"
	}
}
;