c# switch problem

后端 未结 8 2376
囚心锁ツ
囚心锁ツ 2020-12-03 18:53

I\'m new to programming and having a problem with the following code:

    private string alphaCoords(Int32 x)
    {
        char alphaChar;

        switch (         


        
8条回答
  •  余生分开走
    2020-12-03 19:06

    The compiler is complaining because alphaChar is possibly undefined -- if it is not one of the values in your switch then it will not have been defined. You can do one of the following things:

    • Set an initial value of char which will be carried through if none of the switch conditions is true.
    • Add a "default" clause to your switch statement.

提交回复
热议问题