Why do you not declare several variables of the same type on the same line?

后端 未结 16 2251
梦谈多话
梦谈多话 2020-12-06 05:41

Why is it bad practice to declare variables on one line?

e.g.

private String var1, var2, var3

instead of:

private          


        
16条回答
  •  误落风尘
    2020-12-06 05:59

    It is bad practice mostly when you can and want to initialize variables on the deceleration. An example where this might not be so bad is:

    string a,b;
    if (Foo())
    {
      a = "Something";
      b = "Something else";
    }
    else
    {
      a = "Some other thing";
      b = "Out of examples";
    }
    

提交回复
热议问题