遍历结构体中的变量
Posted song2013
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了遍历结构体中的变量相关的知识,希望对你有一定的参考价值。
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 ()
{
//遍历结构体中的变量
{
[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);
}
1
2
3
4
|
foreach
(System.Reflection.FieldInfo fieldInfo
in
typeof
(Site).GetFields())
{
System.Console.Write(fieldInfo.Name);
}
|
foreach (System.Reflection.FieldInfo fieldInfo in typeof(Site).GetFields())
{System.Console.Write(fieldInfo.GetValue(site对象实例).ToString());
}
以上是关于遍历结构体中的变量的主要内容,如果未能解决你的问题,请参考以下文章