下面是用C#实现以上功能的代码示例:

using System;
using System.Collections.Generic;

public class Student
{
    public string Name { get; set; }
    public double Grade { get; set; }
    public string Address { get; set; }
    public string Contact { get; set; }
    public string School { get; set; }

    public void DisplayInfo()
    {
        Console.WriteLine("Name: " + Name);
        Console.WriteLine("Grade: " + Grade);
        Console.WriteLine("Address: " + Address);
        Console.WriteLine("Contact: " + Contact);
        Console.WriteLine("School: " + School);
        Console.WriteLine();
    }
}

public class Program
{
    public static void Main(string[] args)
    {
        List<Student> students = new List<Student>();

        // 输入学生信息
        Console.WriteLine("Enter student information:");
        while (true)
        {
            Student student = new Student();

            Console.Write("Name: ");
            student.Name = Console.ReadLine();

            Console.Write("Grade: ");
            student.Grade = double.Parse(Console.ReadLine());

            Console.Write("Address: ");
            student.Address = Console.ReadLine();

            Console.Write("Contact: ");
            student.Contact = Console.ReadLine();

            Console.Write("School: ");
            student.School = Console.ReadLine();

            students.Add(student);

            Console.WriteLine("Do you want to enter another student? (Y/N)");
            string answer = Console.ReadLine();
            if (answer.ToLower() == "n")
                break;
        }

        // 输出所有学生信息
        Console.WriteLine("All student information:");
        foreach (Student student in students)
        {
            student.DisplayInfo();
        }

        // 查询学生信息
        Console.Write("Enter student name to search: ");
        string searchName = Console.ReadLine();

        bool found = false;
        foreach (Student student in students)
        {
            if (student.Name == searchName)
            {
                Console.WriteLine("Found student information:");
                student.DisplayInfo();
                found = true;
                break;
            }
        }

        if (!found)
        {
            Console.WriteLine("Student not found!");
        }
    }
}

这个代码示例中,首先定义了一个Student类,包含了名字、成绩、地址、家庭联系方式和学校这五个字段,以及一个用于显示学生信息的方法DisplayInfo()。

在Main()方法中,首先创建了一个存储学生对象的列表students。然后通过循环,让用户输入多个学生的信息,并将每个学生对象添加到列表中。

接下来,遍历列表,使用DisplayInfo()方法输出所有学生的信息。

最后,用户可以输入学生姓名进行查询,程序会遍历列表,找到匹配的学生并输出其信息。如果没有找到匹配的学生,则输出"Student not found!"

C# 用类实现下面的功能通过界面输入多个学生信息名字成绩地址家庭联系方式学校 然后输出所有学生信息到界面上查询学生的信息输入学生姓名显示该学生所有相关信息提示步骤:创建一个学生类里面包含5个字段:名字成绩地址家庭联系方式学校包含一个方法:显示学生信息实例化学生调用方法输出学生所有信息若有多个学生循环输出多个学生信息

原文地址: https://www.cveoy.top/t/topic/hWBJ 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录