ParameterInfo.Position Property
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Gets the zero-based position of the parameter in the formal parameter list.
Assembly: mscorlib (in mscorlib.dll)
Only parameters in the method signature (that is, in the formal parameter list) are considered when calculating the position. For instance methods, the hidden parameter that represents this (Me in Visual Basic) is not counted.
To get the ParameterInfo array, first get the method or the constructor, and then call MethodBase.GetParameters.
The following example defines a method with four parameters and displays various properties, including the Position property to display the positions of the parameters.
Note: |
|---|
To run this example, see Building examples that have static TextBlock controls for Windows Phone 8. |
Imports System.Reflection Imports System.Runtime.InteropServices Class Example Public Shared Sub mymethod(ByVal str1 As String, ByRef str2 As String, _ <Out> ByRef str3 As String, <InAttribute> ByVal str4 As String) ' Add str1 to str2, which is ByRef. str2 &= str1 ' When mymethod is called, str3 has no value. Give it one. str3 = "new value" End Sub Public Shared Sub Demo(ByVal outputBlock As System.Windows.Controls.TextBlock) ' Get the method. Dim mm As MethodInfo = GetType(Example).GetMethod("mymethod") ' Display the method. outputBlock.Text &= "MethodInfo.ToString(): " & mm.ToString() & vbCrLf For Each param In mm.GetParameters() outputBlock.Text &= String.Format("Attributes for parameter {0}, ""{1}"": {2} ({3})", _ param.Position, param.Name, param.Attributes, CInt(param.Attributes)) If param.ParameterType.IsByRef Then outputBlock.Text &= "; the parameter type is ByRef" & vbLf Else outputBlock.Text &= vbLf End If Next End Sub End Class ' This code produces the following output: ' 'MethodInfo.ToString(): Void mymethod(System.String, System.String ByRef, System.String ByRef) 'Attributes for parameter 0, "str1": None (0) 'Attributes for parameter 1, "str2": None (0); the parameter type is ByRef 'Attributes for parameter 2, "str3": Out (2); the parameter type is ByRef 'Attributes for parameter 3, "str4": In (1)
Note: