In C#, why is String a reference type that behaves like a value type?

后端 未结 12 2354
抹茶落季
抹茶落季 2020-11-22 02:04

A String is a reference type even though it has most of the characteristics of a value type such as being immutable and having == overloaded to compare the text rather than

12条回答
  •  逝去的感伤
    2020-11-22 02:53

    Also, the way strings are implemented (different for each platform) and when you start stitching them together. Like using a StringBuilder. It allocats a buffer for you to copy into, once you reach the end, it allocates even more memory for you, in the hopes that if you do a large concatenation performance won't be hindered.

    Maybe Jon Skeet can help up out here?

提交回复
热议问题