以十六进制值表示的int枚举 [英] Enum with int represented as hex values
本文介绍了以十六进制值表示的int枚举的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有以下枚举
public enum GridType
{
Walkable = 0xFF000000,
UnWalkable = 0xFF00000,
Walked = 0xFF00000,
Start = 0xFF00000,
Destination = 0xFF00000
}
int值表示argb颜色值。 (我知道它们是相同的值,稍后会放入实际值中)
但是编译器会抛出错误:
The int values represent argb color values. (I know they are the same values, Ill put in the real ones later)
However the compiler throws an error:
不能将类型'uint'隐式转换为'int'。存在显式转换
(您是否缺少演员表?)
该如何解决?
推荐答案
您可以将您的 GridType
使用 uint
:
public enum GridType: uint
{
Walkable = 0xFF000000,
// etc
}
请参见 http ://msdn.microsoft.com/zh-cn/library/vstudio/sbbt4032(v = vs.100).aspx
我认为您可以强制转换,但是根据评论,这是行不通的。
I thought you could cast, but according to comments, that won't work.
这篇关于以十六进制值表示的int枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文