#1 :在.Net Framework中,字符总是表示成16位Unicode的代码
#2 :String 和string 其实是一样的只是表现形式上不同
#3 :string类型被视为基元类型,也就是编译器允许在源代码中直接使用字面值表示字符串,编译器将这些字符串放到模块的元数据中,并在运行时加载和引用它们。
1 static void Main(string[] args) 2 { 3 string s = "2"; 4 Console.WriteLine(s); 5 Console.ReadLine(); 6 }
il查看如下:
1 .method private hidebysig static void Main(string[] args) cil managed 2 { 3 .entrypoint 4 // 代码大小 21 (0x15) 5 .maxstack 1 6 .locals init ([0] string s) 7 IL_0000: nop 8 IL_0001: ldstr "2" 9 IL_0006: stloc.010 IL_0007: ldloc.011 IL_0008: call void [mscorlib]System.Console::WriteLine(string) 12 IL_000d: nop 13 IL_000e: call string [mscorlib]System.Console::ReadLine() 14 IL_0013: pop 15 IL_0014: ret 16 } // end of method Program::Main
IL指令构造对象的新实例是newobj 上面的IL中并没有newobj IL为 ldstr 也就是CLR 用一种特殊的方式构造了string对象
#4:string 中的 + 操作符的实质
1 static void Main(string[] args) 2

