Get the name of the parameter in CSharp
Description
The following code shows how to get the name of the parameter.
Example
using System;//w w w .ja v a 2s . c o m
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)
{
Type Mytype = Type.GetType("parminfo");
MethodBase Mymethodbase = Mytype.GetMethod("mymethod");
Console.Write("\nMymethodbase = " + Mymethodbase);
ParameterInfo[] Myarray = Mymethodbase.GetParameters();
foreach (ParameterInfo Myparam in Myarray)
{
Console.Write ("\nFor parameter # " + Myparam.Position
+ ", the Name is - " + Myparam.Name);
}
return 0;
}
}
The code above generates the following result.