您的位置:首页 > 其它

遍历结构体中的变量

2016-03-17 23:32 344 查看
public struct Site
{
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 30)]
public string Country;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 10)]
public string StationNumber;
[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 20)]
public string RadarType;

public int LongitudeValue;
public short MangFreq;
}

for ()
{
//遍历结构体中的变量

}

遍历结构体成员名称
foreach (System.Reflection.FieldInfo fieldInfo in typeof(Site).GetFields())

{
System.Console.Write(fieldInfo.Name);
}

C# code

?

遍历结构体实例成员值

foreach (System.Reflection.FieldInfo fieldInfo in typeof(Site).GetFields())

{
System.Console.Write(fieldInfo.GetValue(site对象实例).ToString());

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: