Получить имена переменных и их значение
Visual Basic .NET
Imports System.Reflection
Public Class Form1
Private s As String = "123"
Private d As Integer = &H10
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
Dim program = New Form1
Dim fields = GetType(Form1).GetFields(BindingFlags.Instance Or BindingFlags.NonPublic)
For Each field In fields
If TypeOf (field.GetValue(Me)) Is String Or TypeOf (field.GetValue(Me)) Is Integer Then
DataGridView1.Rows.Add(field.Name, field.GetValue(Me))
End If
Next
End Sub
End Class |
|