Switch statement with static fields

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

    I know this is an old question but there is a way that wasnt covered in the other answers that doesnt involve changing the approach:

    switch(pid)
    {
       case var _ when pid == PID_1:
          //Do something 1
       break;
    }
    

提交回复
热议问题