declaring var inside if statement c#

前端 未结 3 1105
遇见更好的自我
遇见更好的自我 2021-01-24 19:11

I have this var, but I want to change it\'s content depending on the statement, I can\'t get it working because when I use it, VS says it has not been declared, even if the stat

3条回答
  •  日久生厌
    2021-01-24 19:35

    Declare the variable outside the if block (without assigning a value - you can't use var in this case though, you'll have to specify the type), and then only assign a value to it inside.

提交回复
热议问题