我是 C# 的初学者,当我遇到这个问题时,我目前正在尝试使用类和数据结构。我想使用提供 char 输入的等级 char 从它的枚举描述中获取 int 输出。欢迎任何帮助。谢谢
using System;
namespace dataStorageOfFiveStudents
{
public class StudentData
{
public string name;
public int rollNo;
public char grade;
public float gpa;
}
public class Program
{
enum grading { A=4, B=3, C=2, D=2, F=0};
static void Main(string[] args)
{
//Data Entry
StudentData student1 = new StudentData();
Console.WriteLine("name?");
student1.name = Console.ReadLine();
Console.WriteLine("Roll Number?");
student1.rollNo = Convert.ToInt32(Console.ReadLine());
Console.WriteLine("Grade");
student1.grade = Convert.ToChar(Console.ReadLine());
student1.gpa = (int)grading.student1.grade;
//Output
Console.WriteLine("Name =\t" + student1.name);
Console.WriteLine("Roll No =\t" + student1.rollNo);
Console.WriteLine("Grade =\t" + student1.grade);
Console.WriteLine("GPA =\t" + student1.gpa);
Console.ReadKey();
}
}
}