enum class in c++ -replacement- in c#

2019-06-24 09:07发布

Take a look at these c++ codes :

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# c++ class enums
1条回答
太酷不给撩
2楼-- · 2019-06-24 09:27

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.

查看更多
登录 后发表回答