C# 结构数组示例
我对c#中的结构有点陌生 我的问题是: 编写一个控制台应用程序,为一组学生接收以下信息: 学生ID、学生姓名、课程名称、出生日期。。 应用程序还应能够显示输入的信息。。 使用structs实现这一点 我一直到现在-->C# 结构数组示例,c#,arrays,struct,C#,Arrays,Struct,我对c#中的结构有点陌生 我的问题是: 编写一个控制台应用程序,为一组学生接收以下信息: 学生ID、学生姓名、课程名称、出生日期。。 应用程序还应能够显示输入的信息。。 使用structs实现这一点 我一直到现在--> 请在这之后帮助我。您已经开始了-现在您只需要填充数组中的每个学生结构: struct student { public int s_id; public String s_name, c_name, dob; } class Program { stati
请在这之后帮助我。您已经开始了-现在您只需要填充数组中的每个
学生
结构:
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();
}
}
}
struct学生
{
公共int s_id;
公共字符串s_name、c_name、dob;
}
班级计划
{
静态void Main(字符串[]参数)
{
学生[]arr=新学生[4];
对于(int i=0;i<4;i++)
{
Console.WriteLine(“请输入StudentId、StudentName、CourseName、出生日期”);
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();
}
}
}
现在,只需再次迭代并将这些信息写入控制台。我会让你们这样做,我会让你们试着制作一个程序来容纳任意数量的学生,而不仅仅是4名学生。给定一个结构实例,你们可以设置值
student thisStudent;
Console.WriteLine("Please enter StudentId, StudentName, CourseName, Date-Of-Birth");
thisStudent.s_id = int.Parse(Console.ReadLine());
thisStudent.s_name = Console.ReadLine();
thisStudent.c_name = Console.ReadLine();
thisStudent.s_dob = Console.ReadLine();
请注意,这段代码非常脆弱,因为我们根本不检查用户的输入。用户不清楚您希望在单独的一行中输入每个数据点。您没有描述要执行的操作。如果你不知道你想做什么,那么你就不能为它写代码。我们也不能。谢谢你的帮助!!
student thisStudent;
Console.WriteLine("Please enter StudentId, StudentName, CourseName, Date-Of-Birth");
thisStudent.s_id = int.Parse(Console.ReadLine());
thisStudent.s_name = Console.ReadLine();
thisStudent.c_name = Console.ReadLine();
thisStudent.s_dob = Console.ReadLine();