Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C# Flags vs FlagsAttribute

Tags:

c#

enums

flags

What's the difference between using Flags and FlagsAttribute with an enum?

like image 999
schnozzinkobenstein Avatar asked Jan 09 '11 19:01

schnozzinkobenstein


1 Answers

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.

like image 200
MikeP Avatar answered Oct 13 '22 16:10

MikeP