c# switch problem

后端 未结 8 2337
囚心锁ツ
囚心锁ツ 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:07

    The compiler has no way of knowing that the variable x can only contain numbers up to 9 (which is what you check in your switch). Since the default case is missing from your switch it can happen that alphaChar remains unassigned. You can either add a default case or assign the variable a value before the switch.

提交回复
热议问题