c# switch problem

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

    Add a default to your switch, because if x is 10, alphaChar will never be assigned.

    0 讨论(0)
  • 2020-12-03 19:24

    Before its first use local variable must be definitely assigned (according to C# specification rules). In this particular case switch construct doesn't guarantee that alphaChar will be definitely assigned thus compiler error. You can provide initial value to alphaChar and thus it will be definitely assigned.

    0 讨论(0)
提交回复
热议问题