c# - C++ 中的枚举类 - 替换 - 在 C# 中

标签 c# c++ class enums

看看这些 c++ 代码:

enum class Flag : int32 {
    f_unread = (1 << 0),
    f_out = (1 << 1),
    f_mentioned = (1 << 4),

    MAX_FIELD = (1 << 4),
};

这些代码在c#中隐藏的是什么?

最佳答案

Using Tangible .看起来差别不大。

[Flags]
public enum Flag : int
{
    f_unread = (1 << 0),
    f_out = (1 << 1),
    f_mentioned = (1 << 4),

    MAX_FIELD = (1 << 4),
}

在c#中,要使用enum作为flags操作的位域,需要添加FlagsAttribute,即添加[FlagsAttribute]或者[Flags]enum 之前。

关于c# - C++ 中的枚举类 - 替换 - 在 C# 中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37387986/

相关文章:

c# - Entity Framework : query against view in EF (C# code) returns duplicate results

c# - LINQ 标量运算

c# - 如何设置值如果组合框不更改 WPF MVVM 模式中的值

c# - PresentationFramework.dll 中发生 System.Windows.Markup.XamlParseException'?

javascript - 未捕获的类型错误 : cannot read 'hasClass' property of undefined

c++ - 如何为可为char或string的模板类实现方法?

c# - 使用多个参数选择返回mysql语法错误

c++ - 使用 std::min_element、std::max_element 查找 vector 中的最小和最大元素

c++ - boost::geometry::covered_by 错误的结果

JavaCompiler - 设置编译类输出文件夹