[c#] Teaching material page77 project training

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Student
    {
        public string name; //field name
        public int age; // field age
        public int _class; // field class
        public long number; //Field student number

        public Student() //Construction method one
        {
            this.name = "Up three"; //Assign default value
            this.age = 11;
            this._class = 2017;
            this.number = 0000;

        }
        public Student(string F2Name, int F2Age, int F2_class, long F2Number) //Construction method 2
        {
            this.name = F2Name; //The actual parameter is assigned to the corresponding field
            this.age = F2Age;
            this._class = F2_class;
            this.number = F2Number;
        }
    }
    class Program
    {
        static void Main(string[] args)
        {
            long sum = 0;
            const int SIZE = 5;
            Student[] a = new Student[SIZE]; //class array
            for (int i = 0; i < SIZE; i++)
            {
                a[i] = new Student(); //Array declaration
                Console.WriteLine("{0}th input data:\nName", i + 1);
                a[i].name=Console.ReadLine(); //Array instantiation
                Console.WriteLine("age");
                a[i].age= int.Parse(Console.ReadLine());
                Console.WriteLine("class");
                a[i]._class= int.Parse(Console.ReadLine());
                Console.WriteLine("学号");
                a[i].number= long.Parse(Console.ReadLine());

                Student c = new Student(a[i].name, a[i].age, a[i]._class, a[i].number);
            }
            for (int i=0;i<SIZE;i++)
            {
                sum += a[i].age; // call age of 10 different objects
            }
            Console.WriteLine(sum/SIZE);
            Console.Read();
        }
    }
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326216234&siteId=291194637