开发者

C# Flags vs FlagsAttribute

开发者 https://www.devze.com 2023-02-03 02:36 出处:网络
What\'s the difference between using Flags 开发者_如何学编程and FlagsAttribute with an enum?Flags is simply shorthand for FlagsAttribute. In C#, you can leave the \"Attribute\" suffix off an attribute

What's the difference between using Flags 开发者_如何学编程and FlagsAttribute with an enum?


Flags is simply shorthand for FlagsAttribute. In C#, you can leave the "Attribute" suffix off an attribute when you're applying it to an element.

As for Flags itself, all it does is denote the enum as having flags members. You still have to ensure that the members have values that combine correctly. Some framework functions, such as Enum.ToString, will look for the flags attribute to determine how to interpret the value.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号