How to give enum values that are having space

前端 未结 5 2024
走了就别回头了
走了就别回头了 2021-01-23 22:39

i have to create an enum that contains values that are having spaces

public enum MyEnum
        {
            My cart,
            Selected items,
            Bi         


        
5条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-23 23:34

    Enum just cant have space! What do you need it for? If you need it simply for display purpose, you can stick with underscore and write an extension method for your enum so that you can ask for the display text by doing this (assuming your ext method is call DisplayText). Internally you just implement the DisplayText method to substitute "_" with space

    MyEnum.My_Cart.DisplayText();   // which return "My Cart"
    

提交回复
热议问题