我想实现的功能如下: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;
} }
}现在编译不通,请问如何实现上述功能?
{
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;
} }
}现在编译不通,请问如何实现上述功能?
{
// 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;
}
{
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;
}
student[i] = new Student(); 可以没有