有2个类
第一个:
class example
    {
        private int id;
        private string name;
        public void goods(int id,string name)
        {
            this.id=id;
            this.name=name;
        }
    } 
如何在第二个类里面用数组的方式添加id 和name
创建数组 example[] a=null ;
后面应该怎么写?c#class

解决方案 »

  1.   

        class example
        {
            public int id;
            private string name;
            public void goods(int id, string name)
            {
                this.id = id;
                this.name = name;
            }
        }    class test
        {
            public void msd()
            {
                example[] a = new example[5];
                for (int i = 0; i < 5; i++)
                {
                    a[i] = new example();
                    a[i].goods(i, i.ToString());
                }
                foreach (example exaa in a)
                {
                    Console.WriteLine(exaa.id.ToString());
                }
            }
        }楼主是这个意思么?
      

  2.   

    class text
    {
      example[] a=new example[3];
    public void()
    {
      for(int i=0;i<3;i++)
    {
      a[i]=new example();
    a[i].goods(i,"name"+i.tostring());
    }
    foreach(example m in a)
    {
       console.writeline(m.id.tostring()+m.name.tostring());
    }
    }
    }
      

  3.   

    我最近测试项目也在弄这个,,一起研究,,你是用到了protoclbuf for C#?