.NET compiler and “Not all code paths return a value”

前端 未结 5 1673
臣服心动
臣服心动 2020-12-11 11:24

Why in code like below is the .NET compiler not able to establish that all code paths do return a value?

bool Test(bool param) {
    bool test = true;
    if         


        
5条回答
  •  鱼传尺愫
    2020-12-11 11:32

    This just represents the limitations in how smart the compiler is with regard to what gets initialized and which lines will be executed.

    I run into this from time to time. But it's very seldom that it's a problem. I would normally just restructure the code a little.

提交回复
热议问题