[RESOLVED] Or'ing Enum Values
Hi,
Let me start by applogizing if I used the wrong terminology when writing "Or'ing", it may be "And'ing". I just know I want it to work how the VB6 MsgBox parameters work.
Anyway, I am making a Library program that will help me organize my Movies, Books and Music and I was looking for a simple way to indicate the various formats that I may have for each item. I will be using a checked listbox to set the formats.
I started down the road of using Enums (see below), but I don't think this will allow me to or various formats together like:
Code:
oAudio.AudioFormat = CAudioItem.AudioFormatEnum.CD | CAudioItem.AudioFormatEnum.MP3;
I am thinking I may have to just define the AudioFormat property as an int and assign the multiple formats as indicated above, but that may not be any better.
So, am I going about this the wrong way? What would be the best way to load these values into the checked listbox, if I can use the Or'ing method.
Code:
public partial class Form1 : Form
{
private void button1_Click(object sender, EventArgs e)
{
CAudioItem oAudio = new CAudioItem();
oAudio.AudioFormat = CAudioItem.AudioFormatEnum.CD;
oAudio = null;
}
}
class CAudioItem
{
public enum AudioFormatEnum { NONE = 0, CD = 1, MP3 = 2, ALBUM = 4};
private AudioFormatEnum _audioFormat;
public AudioFormatEnum AudioFormat
{
get { return _audioFormat; }
set { _AudioFormat = value; }
}
}
Thanks,
CT