Does C# System.String Instances Really End Up on the Heap?
问题 Let's consider some very simple C# code: static void Main(string[] args) { int i = 5; string s = "ABC"; bool b = false; } Jeffrey Richter's " CLR via C# " (Chapter 14) states that " The String type is derived immediately from Object, making it a reference type, and therefore, String objects (its array of characters) always live in the heap, never on a thread's stack ". Also referring to strings, on an example in the book quite similar to the one above: " The newobj IL instruction constructs a