加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

c#使用ConsoleColor作为int

发布时间:2020-12-16 01:28:17 所属栏目:百科 来源:网络整理
导读:参见英文答案 Cast int to enum in C#????????????????????????????????????24个 有什么方法可以使用ConsoleColors作为它们的Ints吗? 喜欢 Console.ForeGroundColor = 10; //ConsoleColor.Green has the Value of 10 但我只能使用 Console.ForeGroundColor
参见英文答案 > Cast int to enum in C#????????????????????????????????????24个
有什么方法可以使用ConsoleColors作为它们的Ints吗?
喜欢

Console.ForeGroundColor = 10; //ConsoleColor.Green has the Value of 10

但我只能使用

Console.ForeGroundColor = ConsoleColor.Green; //when hovering over "Green" Visual Studio even shows me that Green is 10

我设法在注册表中找到这些Color-Ints(HKEY_CURRENT_USER / Console),其中Ints有颜色的hexCodes,但没有名称(我可以将Green的值更改为Orange并返回默认值,但不会无所谓).那么为什么C#或Visual Studio不允许我使用Ints?或者我做错了什么?

请尝试解释它而不使用引用枚举.我知道,这些颜色名称是枚举,但我还不了解枚举转换

解决方法

我使用Vs 2017:我写道

Console.ForegroundColor = (ConsoleColor)10;
Console.ForegroundColor = (ConsoleColor)12;

并且工作了!

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读