我有以下枚举:
public enum BikeType : byte
{
Road = 0,
Mountain = 1
};
Run Code Online (Sandbox Code Playgroud)
当我尝试将它传递给我时,我检索字节的'字符串'表示,而不是数字值:
string str = string.Format("Road bike has a byte value of {0}", BikeType.Road);
"Road bike has a byte value of Road"
Run Code Online (Sandbox Code Playgroud)
我想要字节值(0).我究竟做错了什么?
谢谢
你需要做int到int
string str =
string.Format("Road bike has a byte value of {0}", (int)BikeType.Road);
Run Code Online (Sandbox Code Playgroud)
如果你不投它,它会调用ToString上BikeType.Road,这将返回Road