枚举.getnames()错误

本文关键字:错误 getnames 枚举 | 更新日期: 2023-09-27 18:14:07

当我尝试编译这段代码时,我得到这个错误。

错误1类型或命名空间名称'transmission'无法找到(您是否缺少using指令或程序集引用?)

我怎样才能纠正这个错误?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace ConsoleApplication1
{
public enum transmission
{
    Manual,
    NonSynchronous,
    Automatic,
    SemiAutomatic,
    Continuously,
    Infinitely,
    Electric,
    Hydrostatic,
    Hydrodynamic,
   }
}
    public class Car
{
    static void Main(string[] args)
    {
        string[] transmissions = Enum.GetNames(typeof(transmission));
        foreach(String transmission in transmissions) {
            Console.WriteLine(transmission);
        }

    }
 }

枚举.getnames()错误

您不在ConsoleApplication1命名空间的范围内。要么将Car类包含到该命名空间,要么调用typeof(ConsoleApplication1.transmission)