Why does the String class not have a parameterless constructor?

前端 未结 8 532
萌比男神i
萌比男神i 2021-01-11 11:07

int and object have a parameterless constructor. Why not string?

8条回答
  •  一生所求
    2021-01-11 11:30

    Because there is no point in doing that.

    string is immutable. Creating an empty string is just useless.

    MSDN:

    Strings are immutable--the contents of a string object cannot be changed after the object is created, although the syntax makes it appear as if you can do this.

    As Jonathan Lonowski pointed out, we have string.Empty for that.

提交回复
热议问题