📜  使用 for 循环显示类的所有成员 vb.net - 任何代码示例

📅  最后修改于: 2022-03-11 14:59:36.503000             🧑  作者: Mango

代码示例1
Public Class [MyClass]
    Private a As String
    Private b As String

    Public Sub New(a As String, b As String)
        Me.a = a
        Me.b = b
    End Sub

    Public Overrides Function ToString() As String
        Dim sb = New StringBuilder()
        For Each item In [GetType]().GetFields(BindingFlags.NonPublic Or BindingFlags.Instance)
             sb.Append(item.Name) _
               .Append("=") _
               .Append(item.GetValue(Me)) _
               .Append(" ")
        Next
        Return sb.ToString()
    End Function