Enum.GetNames() 错误
当我尝试编译这段代码时, 我收到这个错误。
错误 1 找不到类型或命名空间名称“传输”(是否缺少 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);
}
}
}
When I try and compile this code,
I get this error.
Error 1 The type or namespace name 'transmission' could not be found (are you missing a using directive or an assembly reference?)
How will I be able to rectify this error?
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);
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您位于
ConsoleApplication1
命名空间的范围之外。将Car
类包含到该命名空间或调用typeof(ConsoleApplication1.transmission)
。You are outside the scope of
ConsoleApplication1
namespace. Either includeCar
class to that namespace or calltypeof(ConsoleApplication1.transmission)
.