我有一个第 3 方对象,它被传递给我的一种方法。该对象包含 20 个左右的字符串成员。如何轻松列出所有字符串名称及其值?
最佳答案
你说的是属性吗?如果是这样,您可以使用反射:
Dim properties = theObject.GetType().GetProperties()
For Each prop In properties
Console.WriteLine("{0}: {1}", prop.Name, _
prop.GetValue(theObject, New Object() { }))
Next
这将通过
GetProperties
返回对象的所有公共(public)属性.
关于vb.net - 列出对象成员和值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6334899/