我想实现的功能如下:namespace MyTest
{
    public struct Student
    {
        public string strName;
        public int iAge;
    };    public partial class Form1 : Form
    {        public Form1()
        {
            InitializeComponent();
        }
        private void button2_Click(object sender, EventArgs e)
        {
            Student st = new Student[10];
            //调用函数给st赋值
            EditStudent(ref st);
            //调用以后st的值已经变成编辑后的内容
            for (int i = 1; i < 10; i++)
            {
                Print(st[i]);
            }
            return;
        }        private void EditStudent(ref Student[] student)
        {
            for (int i = 0; i < 10; i++)
            {
                //
                student[i].strName = "...";
                student[i].iAge = 20 + i;
            }
            return;
        }    }
}现在编译不通,请问如何实现上述功能?

解决方案 »

  1.   

    数组本来就是引用传递。Student st = new Student[10];===》Student[] st = new Student[10];
      

  2.   

    private void button1_Click(object sender, EventArgs e)
            {
               // LockWorkStation();
                Student[] st = new Student[10];
                //调用函数给st赋值
                EditStudent(ref st);
                //调用以后st的值已经变成编辑后的内容
                for (int i = 1; i < 10; i++)
                {
                    //Print(st[i]);
                }
                //return;        }        private void EditStudent(ref Student[] student)
            {
                for (int i = 0; i < 10; i++)
                {
                    //
                    student[i].strName = "...";
                    student[i].iAge = 20 + i;
                }
                return;
            }    }
        struct Student {
           public string strName;
            public int iAge;
        }
      

  3.   

    private void button2_Click(object sender, EventArgs e)
            {
                Student[] st = new Student[10];
                //调用函数给st赋值
                EditStudent(ref st);
                //调用以后st的值已经变成编辑后的内容
                for (int i = 1; i < 10; i++)
                {
                    Print(st[i]);
                }
                return;
            }private void EditStudent(ref Student[] student)
            {
                for (int i = 0; i < 10; i++)
                {
                    //
                    student[i] = new Student();
                    student[i].strName = "...";
                    student[i].iAge = 20 + i;
                }
                return;
            }
      

  4.   

    回4楼,结构中,可以不初始化
    student[i] = new Student(); 可以没有