get value from c# enums

后端 未结 6 2126
无人共我
无人共我 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:01

    With Formatting:

    ((int)ProductionStatus.Validated).ToString("000",  CultureInfo.InvariantCulture);
    

    That's short and simple, and it returns a string.

    You can factor that into an extension method if you like

    public static class ProdStatusExtensions {
        public static string (this ProductionStatus status) {
            return ((int)status).ToString ("000",  CultureInfo.InvariantCulture);
        }
    }
    

提交回复
热议问题