这是我上的课:
class student
{
public string Name;
public int Age;
public enum Gender
{
male,
female,
other
}
public void Write()
{
Console.WriteLine("Name: {0}, Age: {1}, ", Name, Age);
}
}
这是主程序:
class Program
{
static void Main(string[] args)
{
student student1 = new student();
student1.Name = "Dan";
student1.Age = 15;
student1.Write();
}
}
运行程序时,主程序的名称和年龄变量将复制到该类的函数Write
中。我正在尝试对枚举值做同样的事情-我想在主程序中编写一个性别变量,并向函数中添加一些内容也可以将其写入,但是我不知道如何使用枚举值。 / p>
如果有人可以帮忙,我很乐意听到您的建议。
答案 0 :(得分:3)
向您的班级添加性别类型:
p7m