public class Example{ public void GenericMethod (X arg1, Y arg2) { // Method body } } // Retrieving the generic arguments of the GenericMethod method MethodInfo method = typeof(Example<>).GetMethod("GenericMethod"); Type[] genericArgs = method.GetGenericArguments();
public class ExampleIn this example, we have a generic class Example with two generic type parameters. We use the typeof operator to retrieve the Type object representing the class. We then pass this object to the GetGenericArguments method to retrieve the Type objects representing the generic type parameters of the class. Package/Library: System.Reflection.{ // Class body } // Retrieving the generic type parameters of the Example class Type[] genericArgs = typeof(Example<,>).GetGenericArguments();