Enum - VS2005 Beta2

  • Thread starter Colin Basterfield
  • Start date
C

Colin Basterfield

Hi,

I have been playing around with Enum and looking at the example in the help

enum Colors { Red = 1, Green = 2, Blue = 4, Yellow = 8 };

Colors myColors = Colors.Red | Colors.Blue | Colors.Yellow;

Console.WriteLine("myColors holds a combination of colors. Namely: {0}",
myColors);

This will display Red | Blue | Yellow

Is there a way of testing what is in myColors on an individual basis?

TIA

Colin B
 
M

Mattias Sjögren

Is there a way of testing what is in myColors on an individual basis?

You mean like

if ((myColors & Colors.Blue) != 0) ...



Mattias
 
C

Colin Basterfield

Hi,

having started out assembler programming, this Flags thing really makes the
whole construct pretty darn sexy!

thanks for that, awesome!
Colin
KH said:
You should use the [Flags] attribute on the enum for this purpose.


Colin Basterfield said:
Hi,

I have been playing around with Enum and looking at the example in the
help

enum Colors { Red = 1, Green = 2, Blue = 4, Yellow = 8 };

Colors myColors = Colors.Red | Colors.Blue | Colors.Yellow;

Console.WriteLine("myColors holds a combination of colors. Namely: {0}",
myColors);

This will display Red | Blue | Yellow

Is there a way of testing what is in myColors on an individual basis?

TIA

Colin B
 
C

Colin Basterfield

thats cool actually, thanks
Colin

KH said:
You should use the [Flags] attribute on the enum for this purpose.


Colin Basterfield said:
Hi,

I have been playing around with Enum and looking at the example in the
help

enum Colors { Red = 1, Green = 2, Blue = 4, Yellow = 8 };

Colors myColors = Colors.Red | Colors.Blue | Colors.Yellow;

Console.WriteLine("myColors holds a combination of colors. Namely: {0}",
myColors);

This will display Red | Blue | Yellow

Is there a way of testing what is in myColors on an individual basis?

TIA

Colin B
 

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