结构数组示例

Unh*_*ion 4 c# arrays struct

我对c#中的结构有点新意.

我的问题是:

编写一个控制台应用程序,它接收一组学生的以下信息:studentid,studentname,coursename,出生日期..应用程序还应该能够显示正在输入的信息.使用结构实现此...

我已经到了这个 - >

struct student
{
    public int s_id;
    public String s_name, c_name, dob;
}
class Program
{
    static void Main(string[] args)
    {
        Console.WriteLine("Please enter StudentId, StudentName, CourseName, Date-Of-Birth");
        s_id = Console.ReadLine();
        s_name = Console.ReadLine();
        c_name = Console.ReadLine();
        s_dob = Console.ReadLine();
        student[] arr = new student[4];
    }
}
Run Code Online (Sandbox Code Playgroud)

这之后请帮帮我..

Nem*_*ric 12

你已经开始了 - 现在你只需要填充student数组中的每个结构:

struct student
{
    public int s_id;
    public String s_name, c_name, dob;
}
class Program
{
    static void Main(string[] args)
    {
        student[] arr = new student[4];

        for(int i = 0; i < 4; i++)
        {
            Console.WriteLine("Please enter StudentId, StudentName, CourseName, Date-Of-Birth");


            arr[i].s_id = Int32.Parse(Console.ReadLine());
            arr[i].s_name = Console.ReadLine();
            arr[i].c_name = Console.ReadLine();
            arr[i].s_dob = Console.ReadLine();
       }
    }
}
Run Code Online (Sandbox Code Playgroud)

现在,再次迭代并将这些信息写入控制台.我会让你这样做,我会让你试着让程序接收任意数量的学生,而不仅仅是4.