我有一个枚举的行星,其中包含所有8个行星:
enum Planet
{
MERCURY, VENUS, EARTH, MARS,
JUPITER, SATURN, URANUS, NEPTUNE
}
我需要采取一个int位置并输出相应的枚举位置行星名称。
因此,如果用户输入2作为位置,而枚举中的位置2为EARTH。它将输出EARTH。
我尝试使用:
// Planetary Position.
Console.Write("Please enter a numeric position: ");
int position = Convert.ToInt32(Console.Read());
// Output of selected planet.
Console.Write(Enum.GetName(typeof(Planet), position));
// Prevents CMD Prompt from closing.
Console.Read();
但是,当您输入数字时,什么也不会发生。
**注意:我们尚未深入研究任何if语句或类似内容。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句