Why are C#/.Net strings length-prefixed and null terminated?

前端 未结 5 798
名媛妹妹
名媛妹妹 2021-02-12 12:34

After reading What's the rationale for null terminated strings? and some similar questions I have found that in C#/.Net strings are, internally, both length-prefixed and nul

5条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-12 13:12

    Length prefixed so that computing length is O(1).

    Null terminated to make marshaling to unmanaged blazing fast (unmanaged likely expects null-terminated strings).

提交回复
热议问题