.NET面试题:什么是反射
2023-07-06
所有的.NET程序集都有元数据信息,这些元数据信息可以通过一种反射的机制进行访问。System.Reflection可以用来浏览元数据信息。
下面是使用反射的实例代码:
Public Class Form1
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
Dim Pobjtype As Type
Dim PobjObject As Object
Dim PobjButtons As New Windows.Forms.Button()
Pobjtype = PobjButtons.GetType()
For Each PobjObject In Pobjtype.GetMembers
LstDisplay.Items.Add(PobjObject.ToString())
Next
End Sub
End Class