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

后端 未结 12 2345
抹茶落季
抹茶落季 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

    It is mainly a performance issue.

    Having strings behave LIKE value type helps when writing code, but having it BE a value type would make a huge performance hit.

    For an in-depth look, take a peek at a nice article on strings in the .net framework.

提交回复
热议问题