- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在尝试将一些 VB.net 代码转换为 C#。我使用 SharpDevelop 来完成繁重的工作;但它生成的代码在某些枚举操作上出现问题,我不确定如何手动修复它。
原始 VB.net 代码:
Enum ePlacement
Left = 1
Right = 2
Top = 4
Bottom = 8
TopLeft = Top Or Left
TopRight = Top Or Right
BottomLeft = Bottom Or Left
BottomRight = Bottom Or Right
End Enum
Private mPlacement As ePlacement
''...
mPlacement = (mPlacement And Not ePlacement.Left) Or ePlacement.Right
生成的 C# 代码:
public enum ePlacement
{
Left = 1,
Right = 2,
Top = 4,
Bottom = 8,
TopLeft = Top | Left,
TopRight = Top | Right,
BottomLeft = Bottom | Left,
BottomRight = Bottom | Right
}
private ePlacement mPlacement;
//...
//Generates CS0023: Operator '!' cannot be applied to operand of type 'Popup.Popup.ePlacement'
mPlacement = (mPlacement & !ePlacement.Left) | ePlacement.Right;
Resharper 建议将 [Flags]
属性添加到枚举;但这样做不会影响错误。
最佳答案
在 VB 中,Not
用于逻辑非和按位非。
在 C# 中,!
是 bool NOT 而 ~
是按位 NOT。
所以只需使用:
mPlacement = (mPlacement & ~ePlacement.Left) | ePlacement.Right;
关于C# 相当于 "Not MyEnum.SomeValue",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13275895/
我有以下枚举: public enum myEnum { ONE("ONE"), TWO("TWO"); private String name; private myEnum
MyEnum.Item.ToString(); nameof(MyEnum.Item); 哪种风格是首选?两者之间有什么实际区别吗? 最佳答案 第一个是运行时调用,它将在运行时意识到它需要返回字符串
我有一个使用泛型的网络层,我正在使用协议(protocol)以便稍后测试它。我已遵循本教程 https://medium.com/thecocoapps/network-layer-in-swift-
我为我的枚举创建了 Enum ToFrendlyString 函数,但我不能在 Linq 中使用。 public enum MyEnum { Queued = 0,
我需要序列化和反序列化Set使用mybatis。序列化时效果很好,但得到 Set反序列化时。这是我的代码: mybatis-config.xml: 我的枚举:
我正在尝试将一些 VB.net 代码转换为 C#。我使用 SharpDevelop 来完成繁重的工作;但它生成的代码在某些枚举操作上出现问题,我不确定如何手动修复它。 原始 VB.net 代码: En
我正在尝试从我正在处理的类(class)中删除警告。 警告如下: Warning C4482: nonstandard extension used: enum 'MyEnum' used in qu
我在我的框架中的一个类中有一个带有原始值的枚举,我想将其与另一个类一起使用。我收到以下错误。 'types' is inaccessible due to 'internal' protection
我有一些模型 Dictionary .当我尝试使用 C# 驱动程序插入 mongoDB 时,出现异常并显示以下消息: When using DictionaryRepresentation.Docum
我有一个枚举定义为: enum AlertInterfaceControllerKey { case Title case Content } 我想在呈现 WKInterfaceCon
我正在使用Spring的BeanPropertyRowMapper将来自数据库的行映射到我的Bean类Employee,Enum有2种类型,Active,Inactive。当 beanproperty
好吧,我想做这个工作 public static void main(String[] args) { int cityId = 1234; switch (cityId) {
更新,添加评论中的问题: what's the best way to get the Map into Map where Foo is an Enum. it just seems awfully
我将 WinGrid 中的一些数据转换为表达式,以便向用户过滤一些输出。 我有一个初始集合(MyObjectType),我应用了一些动态过滤器,并获得了一个过滤集合。 但是,我遇到了枚举 - MyOb
我想用一些Map如@RequestParam在我的 Spring Controller 中。现在我做了以下事情: public enum MyEnum { TESTA("TESTA"),
对于撇油器。问题位于粗体文本之后的底部附近。 我正在对 ComboBox 进行数据绑定(bind)使用 ObjectDataProvider 转换为枚举类型. ObjectDataProvider很简
我们是否应该使用 Enum 作为 HashMap 中的键存储数据来代替字符串键 Ex。 HashMap myMap 与字符串相比,在 HashMap 中使用枚举作为键是否存在任何性能问题。哪一种是使用
我一直在尝试重载运算符 #include /* (global scope) */ enum class enum_type_1 { e1_enumerand }; inline std::ostr
我是一名优秀的程序员,十分优秀!