class Program
{
static void Main(string[] args)
{
String s = "a";
s = "abcd";
}
}
01 .method private hidebysig static void Main(string[] args) cil managed
02 {
03 .entrypoint
04 // 代码大小 14 (0xe)
05 .maxstack 1
06 .locals init ([0] string s)
07 IL_0000: nop
08 IL_0001: ldstr "a"
09 IL_0006: stloc.0
10 IL_0007: ldstr "abcd"
11 IL_000c: stloc.0
12 IL_000d: ret
13 } // end of method Program::Main
String s = "a";
s = "abcd";
.locals init ([0] string s1)
IL_0000: nop
IL_0001: ldstr "ab"
IL_0006: stloc.0
IL_0007: ldloc.0
IL_0008: ldstr "cd"
IL_000d: call string [mscorlib]System.String::Concat(string,
string)
IL_0012: stloc.0
IL_0013: ret
.locals init ([0] string s1)
IL_0000: nop
IL_0001: ldstr "abcd"
IL_0006: stloc.0
IL_0007: ret
String str = "100+100=" + 200;
Console.Writeline(str);
.maxstack 2
.locals init ([0] string str)
IL_0000: nop
IL_0001: ldstr "100+100="
IL_0006: ldc.i4 0xc8
IL_000b: box [mscorlib]System.Int32
IL_0010: call string [mscorlib]System.String::Concat(object,
object)
IL_0015: stloc.0
IL_0016: ldloc.0
IL_0017: call void [mscorlib]System.Console::WriteLine(string)
IL_001c: nop
IL_001d: ret
String str = "100+100=";
Console.Write(str);
Console.WriteLine(200);
.maxstack 1
.locals init ([0] string str)
IL_0000: nop
IL_0001: ldstr "100+100="
IL_0006: stloc.0
IL_0007: ldloc.0
IL_0008: call void [mscorlib]System.Console::Write(string)
IL_000d: nop
IL_000e: ldc.i4 0xc8
IL_0013: call void [mscorlib]System.Console::WriteLine(int32)
IL_0018: nop
IL_0019: ret
String str ="";
for (int i = 1; i <= 10; i++)
{
str += i;
if(i<10)
str += "+";
}
//预先分配1K的内存空间
StringBuilder sb = new StringBuilder(1024);
for (int i = 1; i <= 10; i++)
{
sb.Append(i);
if(i<10)
sb.Append("+");
}
String result = sb.ToString();