STATIC_READONLY_STRING = CONST_STRING =
編譯並運行:
C:\Users\de\Desktop\bao>csc /t:library /nologo ClassA1.cs
C:\Users\de\Desktop\bao>csc /r:ClassA1.dll /nologo ClassB1.cs
C:\Users\de\Desktop\bao>ClassB1
ClassA1.CONST_STRING = CONST_STRING
ClassA1.STATIC_READONLY_STRING = STATIC_READONLY_STRING
C:\Users\de\Desktop\bao>
重新編輯ClassA1.cs
STATIC_READONLY_STRING = CONST_STRING =
重新編譯ClassA1.cs,並運行ClassB1.exe:
C:\Users\de\Desktop\bao>csc /t:library /nologo ClassA1.cs
C:\Users\de\Desktop\bao>ClassB1
ClassA1.CONST_STRING =
ClassA1.STATIC_READONLY_STRING =
C:\Users\de\Desktop\bao>
????
反編譯打開ClassB1.exe
C:\Users\de\Desktop\bao>ildasm
C:\Users\de\Desktop\bao>
打開ClassB1.exe後,view/metainfo/show! (Ctrl + M)
在metainfo的最底部有這麼一節:
User Strings
-------------------------------------------------------
70000001 : (64) L"ClassA1.CONST_STRING = {0}\r\nClassA1.STATIC_READONLY_STRING = {1}"
70000084 : (12) L""
以及ClassB1.ShowClassA1對應的IL代碼
.method public hidebysig static void ShowClassA1() cil managed
{
// Code size 23 (0x17)
.maxstack 8
IL_0000: nop
IL_0001: ldstr "ClassA1.CONST_STRING = {0}\r\nClassA1.STATIC_READONL"
+ "Y_STRING = {1}"
IL_0006:
IL_000b:
IL_0010: call void [mscorlib]System.Console::WriteLine(string,
object,
object)
IL_0015: nop
IL_0016: ret
} // end of method ClassB1::ShowClassA1
結束語:.NET字符串駐留機制