本文整理汇总了VB.NET中System.Reflection.FieldInfo.GetValue方法的典型用法代码示例。如果您正苦于以下问题:VB.NET FieldInfo.GetValue方法的具体用法?VB.NET FieldInfo.GetValue怎么用?VB.NET FieldInfo.GetValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Reflection.FieldInfo
的用法示例。
在下文中一共展示了FieldInfo.GetValue方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的VB.NET代码示例。
示例1: Example
' 导入命名空间
Imports System.Reflection
Class Example
Public Shared val As String = "test"
Public Shared Sub Main()
Dim fld As FieldInfo = GetType(Example).GetField("val")
Console.WriteLine(fld.GetValue(Nothing))
val = "hi"
Console.WriteLine(fld.GetValue(Nothing))
End Sub
End Class
输出:
test hi
示例2: FieldsClass
' 导入命名空间
Imports System.Reflection
Public Class FieldsClass
Public fieldA As String
Public fieldB As String
Public Sub New()
fieldA = "A public field"
fieldB = "Another public field"
End Sub
End Class
Public Module Example
Public Sub Main()
Dim fieldsInst As New FieldsClass()
' Get the type of FieldsClass.
Dim fieldsType As Type = GetType(FieldsClass)
' Get an array of FieldInfo objects.
Dim fields As FieldInfo() = fieldsType.GetFields(BindingFlags.Public Or BindingFlags.Instance)
' Display the values of the fields.
Console.WriteLine("Displaying the values of the fields of {0}:", fieldsType)
For i As Integer = 0 To fields.Length - 1
Console.WriteLine(" {0}:{2}'{1}'",
fields(i).Name, fields(i).GetValue(fieldsInst), vbTab)
Next
End Sub
End Module
输出:
Displaying the values of the fields of FieldsClass: fieldA: 'A public field' fieldB: 'Another public field'