枚举类在c ++ -replacement-在c# [英] enum class in c++ -replacement- in c#

查看:144
本文介绍了枚举类在c ++ -replacement-在c#的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

查看这些 c ++ 代码:

 枚举类标志:int32 {
f_unread =(1 << 0),
f_out =(1 << 1),
f_上述=(1 <4),
$ b b MAX_FIELD =(1 << 4),
};

c#中的代码是什么?

解决方案

使用有形。看起来没有太大的不同。

  [Flags] 
public enum Flag:int
{
f_unread =(1 << 0),
f_out =(1 <1),
f_ mentioned =(1≤4),
$ b $ c MAX_FIELD =(1 <4),
}



<使用 enum 作为标志操作的位字段,应该添加 FlagsAttribute ,它添加 c>之前 c> c> c> b $ b

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#?

解决方案

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 ++ -replacement-在c#的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆