c#学生运动会管理系统
时间: 2024-01-01 12:04:12 浏览: 64
C#学生运动会管理系统是一个用于管理学生运动会活动的软件系统。它可以帮助学校或组织方便地组织和管理各种运动会项目、参赛学生信息、成绩统计等。
以下是一个简单的C#学生运动会管理系统的示例:
```csharp
using System;
using System.Collections.Generic;
namespace StudentSportsManagementSystem
{
class Program
{
static void Main(string[] args)
{
List<Student> students = new List<Student>();
while (true)
{
Console.WriteLine("请选择操作:");
Console.WriteLine("1. 添加学生");
Console.WriteLine("2. 显示所有学生");
Console.WriteLine("3. 退出");
string choice = Console.ReadLine();
switch (choice)
{
case "1":
AddStudent(students);
break;
case "2":
DisplayStudents(students);
break;
case "3":
Environment.Exit(0);
break;
default:
Console.WriteLine("无效的选择,请重新输入!");
break;
}
}
}
static void AddStudent(List<Student> students)
{
Console.WriteLine("请输入学生姓名:");
string name = Console.ReadLine();
Console.WriteLine("请输入学生年龄:");
int age = int.Parse(Console.ReadLine());
Console.WriteLine("请输入学生性别:");
string gender = Console.ReadLine();
Student student = new Student(name, age, gender);
students.Add(student);
Console.WriteLine("学生添加成功!");
}
static void DisplayStudents(List<Student> students)
{
Console.WriteLine("所有学生信息如下:");
foreach (Student student in students)
{
Console.WriteLine($"姓名:{student.Name},年龄:{student.Age},性别:{student.Gender}");
}
}
}
class Student
{
public string Name { get; set; }
public int Age { get; set; }
public string Gender { get; set; }
public Student(string name, int age, string gender)
{
Name = name;
Age = age;
Gender = gender;
}
}
}
```
这个示例中,我们使用了一个`List<Student>`来存储学生信息。通过菜单选择,用户可以选择添加学生、显示所有学生或退出程序。添加学生时,用户需要输入学生的姓名、年龄和性别。显示所有学生时,系统会遍历学生列表并输出每个学生的信息。