且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

VB.NET 遍历结构的对象

更新时间:2022-06-22 10:22:07

如果这只是一次性的事情,您可能会更轻松地使用字典,但如果您愿意,可以使用反射来做到这一点保持结构.

If this is just a one time thing you're probably going to have an easier time using a Dictionary instead, but you could do this with Reflection if you prefer to keep the structure.

这个小代码片段将在 StringBuilder 中为您列出每个结构成员.

This little code snippet will list out each structure member for you in a StringBuilder.

Dim sbOutput As New System.Text.StringBuilder
Dim t As Type = GetType(xyz)
For Each p As System.Reflection.FieldInfo In t.GetFields()
  sbOutput.AppendLine(p.Name)
Next