Enum with underlying type. Returning the string representation unintentionally
本问题已经有最佳答案,请猛点这里访问。
我有以下枚举:
1 2 3 4 5 | public enum BikeType : byte { Road = 0, Mountain = 1 }; |
当我尝试将它传递给时,我检索字节的"字符串"表示形式,而不是数值:
1 | "Road bike has a byte value of Road" |
我想要字节值(0)。我做错什么了?
谢谢
你需要做整型
1 2 | string str = string.Format("Road bike has a byte value of {0}", (int)BikeType.Road); |
如果你不施法,它会在
你应该投给
1 | string str = string.Format("Road bike has a byte value of {0}", (byte)BikeType.Road); |