get value from c# enums

后端 未结 6 2027
无人共我
无人共我 2021-01-18 05:39

I have an enum

public enum ProductionStatus {
    Received = 000,
    Validated = 010,
    PlannedAndConverted = 020,
    InProduction = 030,
    QAChecked          


        
6条回答
  •  北荒
    北荒 (楼主)
    2021-01-18 06:03

    In general there is an Enum Class that contains an array of methods facilitating the work with enums.

    Here, if you want to cast enumerable value to integer or other type, you can write:

    int validatedAsInt = (int) ProductionStatus.Validated
    

    validatedAsInt will contain value of ProductionStatus.Validated.

    If you want to obtain numbers like "010" you can write:

    string validatedAsString = ((int) ProductionStatus.Validated).ToString("000");
    

    Or:

    string validatedAsString = ((int) ProductionStatus.Validated).ToString("D3");
    

    validatedAsString will contain "010".

提交回复
热议问题