I got the following enum:
public enum detallistaDocumentStatus {
/// <remarks/>
ORIGINAL,
/// <remarks/>
COPY,
/// <remarks/>
REEMPLAZA,
/// <remarks/>
DELETE,
}
then I got a class property of type detallistaDocumentStatus:
public detallistaDocumentStatus documentStatus {
get {
return this.documentStatusField;
}
set {
this.documentStatusField = value;
}
}
In the real life the user will send us a number (1, 2, 3 or 4) representing each enum value in the order they are declared.
so, is it possible to cast like this?
det.documentStatus = (detallistaDocumentStatus)3;
if not, how could I get the enum value using an integer as an index, we are using a lot of enums, so we want to do something generic and reusable
Yes, it’s possible to cast
Enumtointand vice versa, because everyEnumis actually represented by anintper default. You should manually specify member values.By default it starts from 0 to N.
It’s also possible to cast
Enumtostringand vice versa.