如果我定义了一个从 short 继承的 enums
,我对 enums
有疑问:
public enum ProyectoEstatus : short
{
EstatusPorDefecto = 26,
AprobadoUnidadNegocio = 6,
CanceladoAreaComercial = 18
}
为什么我不能这样做??
Nullable<short> aux = ProyectoEstatus.CanceladoAreaComercial as ProyectoEstatus;
如果我的名为 aux 的变量类型是 Nullable
最佳答案
首先,enum
类型本身不可为空,因此 as
运算符(operator)不会处理它。
其次,enum
type 实际上不是 short
.这是一个short
-backed enum 类型,但它需要显式转换为 short 才能接受来自 short
的隐式转换至 Nullable<short>
:
Nullable<short> aux = (short)ProyectoEstatus.CanceladoAreaComercial
关于c# - 使用枚举处理强类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9178832/