ParameterInfo.Name Property

Gets the name of the parameter.

Namespace:  System.Reflection
Assembly:  mscorlib (in mscorlib.dll)

public virtual string Name { get; }

Property Value

Type: System.String
The simple name of this parameter.

This property utilizes the protected NameImpl field, and depends on an optional metadata flag that might not be available in all compilers.

To get the ParameterInfo array, first get the method or the constructor and then call the MethodBase.GetParameters method.

Caution noteCaution

If this ParameterInfo represents a return value (that is, if it was obtained by using the MethodInfo.ReturnParameter property), this property will be null.

The following example shows how to get ParameterInfo objects for the parameters of a method, and then use the Name property to obtain the parameter names.

using System;
using System.Reflection;

class parminfo
{
    public static void mymethod (
       int int1m, out string str2m, ref string str3m)
    {
       str2m = "in mymethod";
    }

    public static int Main(string[] args)
    {   
       Console.WriteLine("\nReflection.Parameterinfo");

       //Get the ParameterInfo parameter of a function. 

       //Get the type.
       Type Mytype = Type.GetType("parminfo");

       //Get and display the method.
       MethodBase Mymethodbase = Mytype.GetMethod("mymethod");
       Console.Write("\nMymethodbase = " + Mymethodbase);

       //Get the ParameterInfo array.
       ParameterInfo[] Myarray = Mymethodbase.GetParameters();

       //Get and display the name of each parameter. 
       foreach (ParameterInfo Myparam in Myarray)
       {
          Console.Write ("\nFor parameter # "   + Myparam.Position 
             + ", the Name is - " +  Myparam.Name);
       }
       return 0;
    }
 }
 /*
 This code produces the following output:

 Reflection.ParameterInfo

 Mymethodbase
 = Void mymethod (Int32, System.String ByRef, System.String ByRef)
 For parameter # 0, the Name is - int1m
 For parameter # 1, the Name is - str2m
 For parameter # 2, the Name is - str3m
 */

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Portable Class Library

Supported in: Portable Class Library

.NET for Windows Store apps

Supported in: Windows 8

.NET for Windows Phone apps

Supported in: Windows Phone 8.1, Windows Phone 8, Silverlight 8.1

Windows Phone 8.1, Windows Phone 8, Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
Show:
© 2014 Microsoft