简体   繁体   English

c ++中的枚举类-replacement- in c#

[英]enum class in c++ -replacement- in c#

Take a look at these c++ codes : 看看这些c ++代码:

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

    MAX_FIELD = (1 << 4),
};

What is the covert of those codes in c# ? c#中这些代码的隐蔽是什么?

Using Tangible . 使用有形 Seems like it is not far different. 似乎它并没有太大的不同。

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

    MAX_FIELD = (1 << 4),
}

In c#, to use enum as bit field for flags operation, it should be added with FlagsAttribute , which adds [FlagsAttribute] or [Flags] before the enum . 在c#中,要将enum用作标志操作的位字段,应该使用FlagsAttribute添加,它在enum之前添加[FlagsAttribute][Flags]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM