结构体数组的初始化,在结构体中加一个构造函数,就可以很轻松的初始化了。要么就得用视图
stu1.stuName="Mary"的句子了,这样子很麻烦!
using System;
using System.Collections;
using System.Text;
using System.Collections;
using System.Text;
namespace MyArray
{
public struct student
{
public string stuName;
public string stuNumber;
public int stuScore;
public student(string stuName, string stuNumber, int stuScore)
{
this.stuName = stuName;
this.stuNumber = stuNumber;
this.stuScore = stuScore;
}
}
class Program
{
static void Main()
{
student[] stu1 = new student[2];
stu1[0] = new student("Tom", "0101001", 96);
stu1[1] = new student("Mary", "0101002", 88);
}
}
}
{
public struct student
{
public string stuName;
public string stuNumber;
public int stuScore;
public student(string stuName, string stuNumber, int stuScore)
{
this.stuName = stuName;
this.stuNumber = stuNumber;
this.stuScore = stuScore;
}
}
class Program
{
static void Main()
{
student[] stu1 = new student[2];
stu1[0] = new student("Tom", "0101001", 96);
stu1[1] = new student("Mary", "0101002", 88);
}
}
}