C#基础问题
- 提问者网友:疯孩纸
- 2021-05-15 12:09
- 五星知识达人网友:一秋
- 2021-05-15 12:52
看看这个行不行:
using System;
using System.Collections.Generic;
using System.Text;
namespace 数组
{
class Program
{
public struct Info
{
public string NumberCode;
public string Name;
public int Cj;
}
static void Main(string[] args)
{
Info[] a = new Info[5];
int i;
for (i = 0; i < 5; i++)
{
Console.WriteLine("请输入学生的学号");
a[i].NumberCode = Console.ReadLine();
Console.WriteLine("请输入学号为{0}的学生姓名",a[i].NumberCode );
a[i].Name = Console.ReadLine();
Console.WriteLine("请输入学号为{0}的学生成绩",a[i].NumberCode);
a[i].Cj = Convert.ToInt32(Console .ReadLine ());
}
for (i = 0; i < 5; i++)
{
Console.WriteLine("学号:{0} 姓名:{1} 成绩:{2}",a[i].NumberCode,a[i].Name,a[i].Cj);
}
}
}
}
不行的话我再修改。嘿嘿。。
- 1楼网友:妄饮晩冬酒
- 2021-05-15 13:11
定义结构:
public struct Info { public string NumberCode; public string Name; public int Cj; } 在按钮单击事件里写代码:
private void button3_Click(object sender, EventArgs e) { Info[] a = new Info[5]; a[0].NumberCode = "00001"; a[0].Name = "张大成"; a[0].Cj = 89; a[1].NumberCode = "00002"; a[1].Name = "戴高乐"; a[1].Cj = 56; a[2].NumberCode = "00003"; a[2].Name = "吴三"; a[2].Cj = 87; a[3].NumberCode = "00004"; a[3].Name = "梅冬青"; a[3].Cj = 77; a[4].NumberCode = "00005"; a[4].Name = "克东"; a[4].Cj = 65;
for (int i = 0; i < 5; i++) { MessageBox.Show("学号:" + a[i].NumberCode + " "+ "姓名:"+ a[i].Name + " " + "成绩:"+ a[i].Cj.ToString()); } }