Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between <Flags> and <FlagsAttribute()>

On the MSDN Enum Class page, there are a couple examples of using Enums with the Flags Attribute. One is written:

<Flags> Public Enum Pets As Integer

and another is written:

<FlagsAttribute()> Enum Colors

The text treats these examples as equivalent. Is there a difference between these forms? Are the parentheses required?

like image 845
Doug Avatar asked Dec 06 '25 13:12

Doug


1 Answers

They are completely equivalent. The conventions are as follows

  1. You don't need the Attribute suffix (ergo the Flags vs FlagsAttribute)
  2. You don't need the parenthesis as it's implied if you aren't passing arguments to the attribute.

Full rules can be found in the documentation. Guidelines for attribute usage.

like image 81
Darren Kopp Avatar answered Dec 10 '25 00:12

Darren Kopp



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!