Switch statement with static fields

前端 未结 7 2043
执念已碎
执念已碎 2021-01-11 14:28

Suppose I have a bunch of static fields and I want to use them in switch:

public static string PID_1 = \"12\";
public static string PID_2 = \"13\";
public st         


        
7条回答
  •  爱一瞬间的悲伤
    2021-01-11 14:42

    Why you don't use enum ?
    Enum keyword:
    http://msdn.microsoft.com/en-us/library/sbbt4032%28v=vs.80%29.aspx

    In your case it can be easily handled over enum:

    public enum MyPidType
    {
      PID_1 = 12,
      PID_2 = 14,
      PID_3 = 18     
    }
    

提交回复
热议问题