Switch statement with static fields

前端 未结 7 1989
执念已碎
执念已碎 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:43

    Case argument should be constant on compile-time.

    Try to use const instead:

    public const string PID_1 = "12";
    public const string PID_2 = "13";
    public const string PID_3 = "14";
    

提交回复
热议问题