Use the FlagsAttribute : attribute « Class « Visual C++ .NET






Use the FlagsAttribute

 

#include "stdafx.h"
using namespace System;


[ Flags ]
enum class Color
{
    Red = 1,
    Blue = 2,
    Green = 4   // use powers of 2
};

int main()
{
   Console::WriteLine("Colors: {0}, {1}, {2}", Color::Red, Color::Blue,Color::Green);
   Console::WriteLine("Colors: {0:d}, {1:d}, {2:d}", Color::Red, Color::Blue,Color::Green);

   Color c = Color::Red | Color::Blue;

   String^ s1 = c.ToString("X"); 
   Console::WriteLine( s1 );


   String^ s2 = Enum::Format( Color::typeid, c , "G");

   Console::WriteLine(s2 );
}

   
  








Related examples in the same category

1.Custom attribute
2.Creating Custom attribute
3.Obsolete attribute
4.Out attribute parameter