if I have a very simple enum of ints like this.
enum alignment { left, center, right}
Where I want the datatype to be an int, which I understand is the default, and the values to be left = 0, center = 1, right = 2.
But if I try and use a value from the enum like
header.Alignment = alignment.center;
I am told that I need to cast alignment.center to an int. which is no big deal but I am wondering if I am doing something wrong or is that just the way enums work.
if
header.Alignmentis of typeint, then yes, you always have to cast to anint.You could make
header.Alignmentof typealignment, and then you’d never have to cast. If you’re dealing with legacy or third-party code that only accepts anint, however, you’re out of luck.