What does the [Flags] attribute actually do?

G

Guest

Hi,

I have used bitfields in C before and I understand all the AND/OR operations
etc. While learning C# I was told to mark all by "bitfield enums" with the
[Flags] attribute. Do why? Exactly what does this attribute do?

The MSDN docs says: " Indicates that an enumeration can be treated as a bit
field; that is, a set of flags." but that really doesn't tell you anything
substantial:
http://msdn2.microsoft.com/en-us/library/system.flagsattribute.aspx

I have tried to use & for enumerations with and without the attribute, both
ways work just fine?!


Regards,
Martin
 
M

Mattias Sjögren

I have tried to use & for enumerations with and without the attribute, both
ways work just fine?!

It affects what the ToString method returns for example.


Mattias
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top