枚举 ConsoleColor - 是这种类型吗?
我知道我可以设置 consele 的属性 ForegroundColor 但我不确定的是:该属性的类型为 enum
或 ConsoleColor,即枚举?我只是不知道我到底在做什么,将属性设置为 consolecolor 的值(这是什么,枚举的实例?枚举?)。 谢谢
I know I can set property ForegroundColor of consele but what I am not sure is: the property is of the type enum
or ConsoleColor, which is enum? I just do not know what I am exactly doing, setting the property to value of consolecolor (what is this, instance of enum? enum?).
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该属性的类型为
ConsoleColor
,它是一个枚举类型。当您使用以下内容设置它时:
您将其设置为
ConsoleColor
类型的值 - 就像其他任何东西一样。ConsoleColor.Red
是 ConsoleColor 类型的值,就像 3 是int
类型的值以及"hi"
是typestring
(尽管在后一种情况下它是对对象的引用,而枚举是值类型)。特别是,您必须将其设置为
ConsoleColor
类型的值,而不是任何其他枚举。例如,这不会编译:The property is of type
ConsoleColor
, which is an enum type.When you set it with something like:
you're setting it to a value of type
ConsoleColor
- just like anything else.ConsoleColor.Red
is a value of type ConsoleColor in the same way that 3 is a value of typeint
and"hi"
is a value of typestring
(although in the latter case it's a reference to an object, whereas enums are value types).In particular, you have to set it to a value of type
ConsoleColor
rather than any other enum. For example, this won't compile: