How to TryParse for Enum value?

前端 未结 14 1009
终归单人心
终归单人心 2020-11-29 00:22

I want to write a function which can validate a given value (passed as a string) against possible values of an enum. In the case of a match, it should return th

14条回答
  •  难免孤独
    2020-11-29 00:49

    enum EnumStatus
    {
        NAO_INFORMADO = 0,
        ENCONTRADO = 1,
        BLOQUEADA_PELO_ENTREGADOR = 2,
        DISPOSITIVO_DESABILITADO = 3,
        ERRO_INTERNO = 4,
        AGARDANDO = 5
    }
    

    ...

    if (Enum.TryParse(item.status, out status)) {
    
    }
    

提交回复
热议问题