相关疑难解决方法(0)

为什么枚举需要显式转换为int类型?

这样做没有数据丢失,那么为什么必须明确地将枚举转换为整数?

如果它是隐含的,那么它是不是更直观,比如当你有更高级别的方法时:

PerformOperation ( OperationType.Silent type )
Run Code Online (Sandbox Code Playgroud)

在哪里PerformOperation调用一个被暴露的包装C++方法:

_unmanaged_perform_operation ( int operation_type )
Run Code Online (Sandbox Code Playgroud)

.net c# enums casting

21
推荐指数
2
解决办法
1万
查看次数

枚举为字典键

假设有

enum SomeEnum { One, Two, Three };
Run Code Online (Sandbox Code Playgroud)

SomeEnum是一个枚举,所以它应该从Enum继承,所以如果我写:

Dictionary<Enum, SomeClass> aDictionary = new Dictionary<SomeEnum, SomeClass>();
Run Code Online (Sandbox Code Playgroud)

编译器抱怨它不能隐式地将SomeEnum转换为Enum?

c# .net-2.0

16
推荐指数
1
解决办法
3万
查看次数

标签 统计

c# ×2

.net ×1

.net-2.0 ×1

casting ×1

enums ×1