What Does the [Flags] Attribute Really Do?

前端 未结 6 1221
闹比i
闹比i 2020-12-06 03:58

What does applying [Flags] really do?

I know it modifies the behavior of Enum.ToString, but does it do anything else? (e.g. Different compiler or runtime behavior, e

6条回答
  •  失恋的感觉
    2020-12-06 04:50

    See David M. Kean's post here. This appears to be a language interop issue:

    Although C# happily allows users to perform bit operations on enums without the FlagsAttribute, Visual Basic does not. So if you are exposing types to other languages, then marking enums with the FlagsAttribute is a good idea; it also makes it clear that the members of the enum are designed to be used together.

    Regards

    David

提交回复
热议问题