calling Enum by value [duplicate]

1

I created an enum:

 public enum EnumTipoBoleto
    {
        VazioErro=0,
        ConfigInicial = 1,
        Mensalidade = 2,
        Outros =3,
        DifMensal =4
    }

Now in some places I have the number and want to convert to enum

var variavel = 2;
var valorEnum = EnumTipoBoleto[variavel]; //Como faço?
'EnumTipoBoleto' is a type, which is not valid in the given context
    
asked by anonymous 30.09.2016 / 15:23

1 answer

1

Try to make a cast

For example:

var variavel = 2;
var valorEnum = (EnumTipoBoleto)variavel;
    
30.09.2016 / 15:29