遍历结构体内部元素和值(Name and Value)
代码:
DataStruct.MessageStruct ms = new DataStruct.MessageStruct();//实例化结构体
//遍历结构体
foreach (System.Reflection.PropertyInfo p in ms.GetType().GetProperties())
{
this.rtbSend.Text += p.Name + "=" + p.GetValue(ms)+"\r\n";
}
运行结果:
![](https://img2018.cnblogs.com/blog/695144/201903/695144-20190322094127917-763411744.png)
posted on 2019-03-22 09:43 Innershar 阅读(1112) 评论(0) 编辑 收藏 举报