Use of Unassigned local variable

前端 未结 3 1257
离开以前
离开以前 2021-01-26 11:52

I encountered an error. Despite declaring the variables (failturetext and userName) errors still appear. Can anyone please help me?

- Use of Unassigned local va         


        
3条回答
  •  故里飘歌
    2021-01-26 12:13

    If you wish to keep the same convention as you have at the moment, then to solve the issue of it failing compilation you want to assign the two variables a null value first before you try to reference them.

    Like so:

    TextBox FailureText = null;
    TextBox UserName = null;
    

    If you do this, you might need to check on whether they are still null when you try and assign the properties of these objects.

    As people above have stated, you should not be doing it this way as UI controls should always be global to the form itself.

提交回复
热议问题