日期:2014-05-17  浏览次数:20903 次

对于有嵌套的结构体,怎么遍历所以的数据呢?
前面发过一个贴如下,
http://bbs.csdn.net/topics/390550449?page=1#post-395330675

如果当前BLC是这样的
struct BLC
{
int a,
int b,
struct DCE dce
struct FG fg;
}
struct DCE
{
int [] haha;
int f;
}
要怎么个循环法呢?谢谢

------解决方案--------------------
在你上个帖子的基础上改了下,说实话,真心不喜欢这种输出,没啥意义:

        public struct BLC
        {
            public int a;
            public int b;
            public DCE dce;
            public FG fg;
        };
        public struct DCE
        {
            public int[] haha;
            public int f;
        };
        public struct FG
        {
            public int[] data;
        }

        static void WriteStructValue(object obj, string pname, StringBuilder sb)
        {
            Type type = obj.GetType();
            string typename = pname + "." + type.Name;
            foreach (FieldInfo mi in type.GetFields(BindingFlags.Public 
------解决方案--------------------
 BindingFlags.Instance))