小编Bru*_*uno的帖子

Is it possible to check for null values in switch case statement in C#

I have an object with the property Value. Value is a nullable number. I have some scenarios for the value of value. Usually, for null cases, I use the default case but this time, it is not correct logically. I want to do "X" in case of 100, "Y" in case of no value (the value is null), otherwise, I want to do "Z".

switch (p.Value)
{
    case 100:
        // DO X
        break;
    default:
        // Do Z
        break;
} …
Run Code Online (Sandbox Code Playgroud)

c# switch-statement

4
推荐指数
1
解决办法
87
查看次数

标签 统计

c# ×1

switch-statement ×1