Should I always/ever/never initialize object fields to default values?

前端 未结 17 2152
臣服心动
臣服心动 2020-12-09 14:49

Code styling question here.

I looked at this question which asks if the .NET CLR will really always initialize field values. (The answer is yes.) But it

17条回答
  •  盖世英雄少女心
    2020-12-09 15:44

    I agree with you; it may be verbose, but I like to see:

    int myBlorgleCount = 0;
    

    Now, I always initial strings though:

    string myString = string.Empty;
    

    (I just hate null strings.)

提交回复
热议问题