如:
struct  A
{
int b;
int c;
byte[] d;}
d怎么初始化啊?
小弟初学,请高手指点一下!!!!

解决方案 »

  1.   

    A a = new A();
    a.d = new byte[100];
    ----------------------------这个和Label[] label 的声明是一样的
      

  2.   

    用属性 
           public byte[] InitD//用属性赋值
            {
                get { return d; }
                set {d = value; }
            }
      

  3.   

    struct A
    {
    int b;
    int c;
    byte[] d = new byte[50];}
    最好先定义数组长度。
      

  4.   

    关键是在C#中,struct A
    {
    int b;
    int c;
    byte[] d = new byte[50];}
    会出错啊!
      

  5.   

    用到的时候再赋值
    A.b=11;
    A.c=11;
      

  6.   

    A a = new A();
    a.d = new byte[100];
    好象不行!
    to 结构的初始化,只能在实例化它时进行,就像其他基础数据类型一样。
    fd7893(看着)
    刚工作,经理给了个结构,让这么做!!!
    怎么在事例时初始化??
      

  7.   

    把你们经理的结构改成这样
        struct A
        {
            public int b;
            public int c;
            public byte[] d;
        }
    你再试试,a.d = new byte[100];应该就可以了。
      

  8.   

    在C# 中 结构的成员的属性默认的也是private。
      

  9.   

    你们经理有病,叫他用类。
    如果你这样定义结构。
    因为数组是引用类型,
    所以,就算你写个有参构造函数来构造这个结构。
    但是结构在值拷贝时只可能拷贝数组的引用,即如果你:A a = new A( null );
    //或者干脆
    A a;A b = a;
    这个时候对b.d的元素的修改都会反映到a.d。
      

  10.   

    struct A{
    int b;
    int c;
    byte[] d;
    public A(int num)
    {
    d = new byte[num];
    }
    }
      

  11.   

    struct  A
    {
    int b;
    int c;
    byte[] d;
    public A(int b,int c)
    {
       this.b=b;
       this.c=c;
       d=new byte[100];
    }}
      

  12.   

    VS2005:
    unsafe struct  A
    {
    int b;
    int c;
    fixed byte d[100];
    }
      

  13.   

    unsafe struct  A
    {
    int b;
    int c;
    fixed byte* d[100];
    }