首页 > 其他 > 详细

遍历结构体中的变量

时间:2016-03-18 00:28:09      阅读:265      评论:0      收藏:0      [点我收藏+]
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 
 
 ?
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());
}
 

遍历结构体中的变量

原文:http://www.cnblogs.com/gosteps/p/5290017.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!