我写的一个C#程序用到结构体声明如下:
public struct head_t
{
public head_t prev, next;
public double[] data;
public int len;
};
VS.Net编译下出错信息为:结构成员“head_t.prev”(属于类型“head_t”)在结构布局中导致循环请问上面代码问题出在哪里?怎么在C#下编写这种需要嵌套自己的结构体?多谢!

解决方案 »

  1.   

    写两个struct吧,貌似嵌套自己不可能
      

  2.   

    还有个解决方案,但是很难看:
    public struct head_t
    {
        object prev, next;
        public head_t Prev
        {
            get 
            {
                if (prev == null)
                    prev = new head_t();
                return (head_t)prev;
            }
            set { prev = value; }
        }
        public head_t Next
        {
            get
            {
                if (next == null)
                    next = new head_t();
                return (head_t)next;
            }
            set { prev = value; }
        }
        public double[] data;
        public int len;
    }