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

前端 未结 5 802
名媛妹妹
名媛妹妹 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:24

    Here is an excerpt from Jon Skeet's Blog Post about strings:

    Although strings aren't null-terminated as far as the API is concerned, the character array is null-terminated, as this means it can be passed directly to unmanaged functions without any copying being involved, assuming the inter-op specifies that the string should be marshalled as Unicode.

提交回复
热议问题