.NET API Reference

Signature

public virtual ParameterInfo[] GetParameters();

Gets an array of ParameterInfo objects that represent the parameters of the method represented by this MethodBase instance.

Remarks

The returned array is ordered the same as the parameters appear in the method declaration. If the method has no parameters, an empty array is returned.

For generic methods, the array includes type parameters as ParameterInfo objects whose ParameterType is a generic type parameter.

Example

The following example enumerates the parameters of a method and prints their names and types.

// Using System.Reflection
using System;
using System.Reflection;

class Sample
{
    public void Demo(int count, string name, double[] values) { }

    static void Main()
    {
        MethodInfo mi = typeof(Sample).GetMethod("Demo");
        ParameterInfo[] parameters = mi.GetParameters();

        Console.WriteLine($"Method: {mi.Name}");
        foreach (var p in parameters)
        {
            Console.WriteLine($"  {p.Name} : {p.ParameterType}");
        }
    }
}

See Also