c#用结构数组存储多个学生的信息每个学生的信息姓名、学号和成绩。输入学生学号,可以输出他姓名,成绩
1个回答
展开全部
见下面的程序
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication13
{
// Student结构
struct Student
{
// 姓名
public string Name;
// 学号
public int ID;
// 成绩
public float Score;
public override string ToString()
{
return string.Format("姓名:{0},学号:{1},成绩:{2}",
Name,
ID,
Score);
}
}
class Program
{
static void Main(string[] args)
{
// 学生结构数组
Student[] students = new Student[5];
students[0] = new Student { Name = "张三", ID = 1, Score = 90 };
students[1] = new Student { Name = "李四", ID = 2, Score = 80 };
students[2] = new Student { Name = "王五", ID = 3, Score = 70 };
students[3] = new Student { Name = "赵六", ID = 4, Score = 60 };
students[4] = new Student { Name = "钱七", ID = 5, Score = 50 };
// 输出
for (int i = 0; i < students.Length; i++)
{
Console.WriteLine(students[i].ToString());
}
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询