I have the following enum:
Expand|Select|Wrap|Line Numbers
- public enum BaudRates : int
- {
- BR1200 = 1200,
- BR2400 = 2400,
- BR4800 = 4800,
- BR9600 = 9600,
- BR19200 = 19200,
- BR3800 = 38400,
- BR57600 = 57600,
- BR115200 = 115200,
- BR230400 = 230400,
- }
Expand|Select|Wrap|Line Numbers
- Array BRs = Enum.GetValues(typeof(BaudRates));
So I figure since my ENUM type is also an int, I'll do this:
Expand|Select|Wrap|Line Numbers
- int[] intBRs (int[])BRs;
intBRs is now usable like a regular int[].
Here is where the confusion comes in. intBRs.GetType() shows type of BaudRate[] and not int[] as it was declared.
Looking at the debug window, it shows BR1200 BR2400 and etc anstead of 1200,2400, etc.
BUT I can say int a= intBRs[0]; and a has the value of 1200 just fine.
Now I know there is implicit conversion involved, but I want to use the intBRs as the datasource for a ComboBox and then set the SelectedItem to mySerialPort.BaudRate.
It cannot do this since the datasource is using BR1200, BR2400.
I can get around it by typecasting mySerialPort.BaudRate as a BaudRates, but I think the intBRs should have really been a int[] not a BaudRates[];
Work around:
Expand|Select|Wrap|Line Numbers
- int[] intBRs = (int[])Enum.GetValues(typeof(BaudRates));
- cbBaudRate.DataSource = (int[])intBRs;
- cbBaudRate.SelectedItem = (BaudRates)_port.BaudRate;
Does anyone have any thoughts on the boxing/unboxing issues