Why compile error “Use of unassigned local variable”?

前端 未结 10 2346
说谎
说谎 2020-11-22 03:16

My code is the following

int tmpCnt;  
if (name == \"Dude\")  
   tmpCnt++;  

Why is there an error Use of unassigned local variabl

10条回答
  •  借酒劲吻你
    2020-11-22 03:57

    The following categories of variables are classified as initially unassigned:

    • Instance variables of initially unassigned struct variables.
    • Output parameters, including the this variable of struct instance constructors.
    • Local variables , except those declared in a catch clause or a foreach statement.

    The following categories of variables are classified as initially assigned:

    • Static variables.
    • Instance variables of class instances.
    • Instance variables of initially assigned struct variables.
    • Array elements.
    • Value parameters.
    • Reference parameters.
    • Variables declared in a catch clause or a foreach statement.

提交回复
热议问题