结合枚举 [英] Combining Enums

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

问题描述

有没有办法来组合枚举在VB.net?

Is there a way to combine Enums in VB.net?

推荐答案

我相信你想要的是一个标志枚举类型。

I believe what you want is a flag type enum.

您需要添加标记属性来枚举的顶部,然后你可以结合枚举与'或'关键字。

You need to add the Flags attribute to the top of the enum, and then you can combine enums with the 'Or' keyword.

这样的:

<Flags()> _
Enum CombinationEnums As Integer
  HasButton = 1
  TitleBar = 2
  ReadOnly = 4
  ETC = 8
End Enum

注意:的数字向右总是两倍大(2的幂) - 这是需要能够分离已经设置了单独标记

Note: The numbers to the right are always twice as big (powers of 2) - this is needed to be able to separate the individual flags that have been set.

联合使用或关键字所需的标志:

Combine the desired flags using the Or keyword:

Dim settings As CombinationEnums
settings = CombinationEnums.TitleBar Or CombinationEnums.Readonly

此设置标题栏,并只读到枚举

This sets TitleBar and Readonly into the enum

要检查什么的被设置:

If (settings And CombinationEnums.TitleBar) = CombinationEnums.TitleBar Then
  Window.TitleBar = True
End If

这篇关于结合枚举的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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