ParameterInfo.ParameterType Property
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Gets the type of this parameter.
Assembly: mscorlib (in mscorlib.dll)
This method depends on optional metadata and might not be available in all compilers.
To get the ParameterInfo array, first get the method or the constructor, and then call MethodBase.GetParameters.
The following example shows how to get ParameterInfo objects for the parameters of a method, and then use the ParameterType property to display the type of each parameter. The example defines a method with three parameters. The first parameter has no attributes, the second is an out parameter (OutAttributeByRef parameter in Visual Basic), and the third is a ref parameter (ByRef parameter in Visual Basic).
Note: |
|---|
To run this example, see Building examples that have static TextBlock controls for Windows Phone 8. |
using System; using System.Reflection; class Example { public static void mymethod( int int1m, out string str2m, ref string str3m) { str2m = "in mymethod"; } public static int Demo(System.Windows.Controls.TextBlock outputBlock) { outputBlock.Text += "\nReflection.Parameterinfo" + "\n"; //Get the ParameterInfo parameter of a function. //Get the type. Type Mytype = Type.GetType("Example"); //Get and display the method. MethodBase Mymethodbase = Mytype.GetMethod("mymethod"); outputBlock.Text += "\nMymethodbase = " + Mymethodbase; //Get the ParameterInfo array. ParameterInfo[] Myarray = Mymethodbase.GetParameters(); //Get and display the ParameterInfo of each parameter. foreach (ParameterInfo Myparam in Myarray) { outputBlock.Text += "\nFor parameter # " + Myparam.Position + ", the ParameterType is - " + Myparam.ParameterType; } return 0; } } /* This code produces the following output: Reflection.Parameterinfo Mymethodbase = Void mymethod(Int32, System.String ByRef, System.String ByRef) For parameter # 0, the ParameterType is - System.Int32 For parameter # 1, the ParameterType is - System.String& For parameter # 2, the ParameterType is - System.String& */
Note: