
- C# Basic Tutorial
- C# - Home
- C# - Overview
- C# - Environment
- C# - Program Structure
- C# - Basic Syntax
- C# - Data Types
- C# - Type Conversion
- C# - Variables
- C# - Constants
- C# - Operators
- C# - Decision Making
- C# - Loops
- C# - Encapsulation
- C# - Methods
- C# - Nullables
- C# - Arrays
- C# - Strings
- C# - Structure
- C# - Enums
- C# - Classes
- C# - Inheritance
- C# - Polymorphism
- C# - Operator Overloading
- C# - Interfaces
- C# - Namespaces
- C# - Preprocessor Directives
- C# - Regular Expressions
- C# - Exception Handling
- C# - File I/O
- C# Advanced Tutorial
- C# - Attributes
- C# - Reflection
- C# - Properties
- C# - Indexers
- C# - Delegates
- C# - Events
- C# - Collections
- C# - Generics
- C# - Anonymous Methods
- C# - Unsafe Codes
- C# - Multithreading
- C# Useful Resources
- C# - Questions and Answers
- C# - Quick Guide
- C# - Useful Resources
- C# - Discussion
What does the [Flags] Enum Attribute mean in C#?
The Enum Flags is used to take an enumeration variable and allow it hold multiple values. It should be used whenever the enum represents a collection of flags, rather than representing a single value
Use the FlagsAttribute for an enumeration only if a bitwise operation (AND, OR, EXCLUSIVE OR) is to be performed on a numeric value.
Define enumeration constants in powers of two, that is, 1, 2, 4, 8, and so on. This means the individual flags in combined enumeration constants do not overlap.
Example
class Program { [Flags] enum SocialMediaFlags { None = 0, Facebook = 1, Twitter = 2, LinkedIn = 4, Instagram = 8, Snapchat = 16, Pinterest = 32, Reddit = 64 } static void Main() { var SocialMedia1 = SocialMediaFlags.Facebook | SocialMediaFlags.Twitter | SocialMediaFlags.Instagram; var SocialMedia2 = SocialMediaFlags.LinkedIn; var SocialMedia3 = SocialMediaFlags.Pinterest | SocialMediaFlags.Reddit; SocialMediaFlags[] SocialMediasFlags = { SocialMedia1, SocialMedia2, SocialMedia3 }; for (int ctr = 0; ctr < SocialMediasFlags.Length; ctr++) if ((SocialMediasFlags[ctr] & SocialMediaFlags.Facebook) == SocialMediaFlags.Facebook) { Console.WriteLine("SocialMedia {0} has Facebook service: {1}", ctr + 1, "Yes"); } Console.WriteLine(); } }
Output
SocialMedia 1 has Facebook service: Yes
- Related Articles
- What does the pandas.series.array attribute do?
- What does the pandas.series.index attribute do?
- What does the pandas.series.values attribute do?
- What does geometry mean?
- What does psychology mean?
- What does humus mean?
- What does the explicit keyword mean in C++?
- What does the KEY keyword mean in MySQL?
- What does the restrict keyword mean in C++?
- What does the volatile keyword mean in C++?
- What does the Star operator mean in Python?
- What does Kicking the Tires mean in Investment?
- What does axes in the pandas series mean?
- What does createdCollectionAutomatically mean in MongoDB?
- What does # mean in Lua programming?

Advertisements