struct Student
{
    string name;
    int[] score;
    public Student(string name,int[] score)
    {
        //指向自身的指针
        this.name = name;
        this.score = score;
    }
    //计算平均分数
    public float avg()
    {
        float num = 0.0f;
        for (int i = 0; i < score.Length; i++)
        {
            num += score[i];
        }
        return num / score.Length;
    }
    public string Name
    {
        get { return name; }
    }
    public int[] Score
    {
        get { return score; }
        set { score = value; }
    }
}
namespace ConsoleApplication3
{
    class StudentTest
    {
        public static void Main()
        {
            Student[] stu = new Student[3];
            string[] name ={ "jack", "mary", "kate" };
            int[] s ={ 80, 80, 80 };
            for (int i = 0; i < 3; i++)
            {
                stu[i] = new Student(name[i], s);
                Console.WriteLine("{0,10}{1,3}",stu[i].Name,stu[i].avg());
            }
        }
    }
}谢谢各位了  拜托!
  
对于结构 真的不是很懂  ……

解决方案 »

  1.   

    ..这注释貌似没话可写额。
                 Student[] stu = new Student[3];//初始化学生结构实例
                string[] name ={ "jack", "mary", "kate" };
                int[] s ={ 80, 80, 80 };
                for (int i = 0; i < 3; i++)
                {
                    stu[i] = new Student(name[i], s);//循环将name数组里的名称与分数初始化
                    Console.WriteLine("{0,10}{1,3}",stu[i].Name,stu[i].avg());//输出学生名,与这个学生的平均分
                }
      

  2.   

    struct Student//结构
    {
        string name;
        int[] score;
        public Student(string name,int[] score)//构造函数
        {
            //指向自身的指针
            this.name = name;
            this.score = score;
        }
        //计算平均分数
        public float avg()
        {
            float num = 0.0f;
            for (int i = 0; i < score.Length; i++)
            {
                num += score[i];
            }
            return num / score.Length;
        }
        public string Name
        {
            get { return name; }//获取字段值
        }
        public int[] Score//设置获取字段值
        {
            get { return score; }
            set { score = value; }
        }
    }
    namespace ConsoleApplication3
    {
        class StudentTest
        {
            public static void Main()
            {
                Student[] stu = new Student[3];
                string[] name ={ "jack", "mary", "kate" };
                int[] s ={ 80, 80, 80 };
                for (int i = 0; i < 3; i++)
                {
                    stu[i] = new Student(name[i], s);//struct变量
                    Console.WriteLine("{0,10}{1,3}",stu[i].Name,stu[i].avg());
                }
            }
        }
    }
      

  3.   

      public string Name
        {
            get { return name; }
        }
        public int[] Score
        {
            get { return score; }
            set { score = value; }
        }属性的作用是什么呀??stu[i] = new Student(name[i], s) 里面的两个参数  怎么可以这样写呢??而且我的是“结构”  怎么在实例化的时候 是数组呢??? 
      

  4.   

    我觉得lz还是装MM求助比较靠谱。
      

  5.   

    晕 不要把结构struct 想的那么恐怖 ...跟类class的用法基本一样平时都用class 没用过struct ,以为struct 是个什么厉害,高深的玩意儿
      

  6.   

    很简单的哇,结构体是学生的信息,avg是求平均成绩
      

  7.   

    struct Student 
    {
        string name;声明下学生姓名
        int[] score;学生成绩
        public Student(string name,int[] score) 建立一个学生类
        {
            //指向自身的指针
            this.name = name;
            this.score = score;
        }
        //计算平均分数
        public float avg()
        {
            float num = 0.0f;
            for (int i = 0; i < score.Length; i++)把每个同学分数都加起来
            {
                num += score[i];
            }
            return num / score.Length;
    返回学生平均成绩
        }
        public string Name
        {
            get { return name; }
        }
        public int[] Score
        {
            get { return score; }
            set { score = value; }
        }
    }
    namespace ConsoleApplication3
    {
        class StudentTest
        {
            public static void Main()
            {
                Student[] stu = new Student[3];
                string[] name ={ "jack", "mary", "kate" };
                int[] s ={ 80, 80, 80 };
                for (int i = 0; i < 3; i++)
                {
                    stu[i] = new Student(name[i], s);
                    Console.WriteLine("{0,10}{1,3}",stu[i].Name,stu[i].avg());通过控制台打印出来这三个同学的姓名以及平均分
                }
            }
        }}
    其实你慢慢分析,就是一个学生信息,然后输入学生成绩,求出学生的平均分,就这样
      

  8.   


    你TMD  没碰见过不懂啊!有种 你不学 进微软啊!