结构体数组的初始化

来源:互联网 发布:数据库between and 编辑:程序博客网 时间:2024/05/20 18:42
结构体数组的初始化,在结构体中加一个构造函数,就可以很轻松的初始化了。要么就得用视图
stu1.stuName="Mary"的句子了,这样子很麻烦!
using System;
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);
        }
    }
}
原创粉丝点击