遍历结构体内部元素和值(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";
}
运行结果: