只是爲了好玩,我跑ILDASM通過兩個版本,看看是否有編譯後的任何差異。正如你所看到的,在輸出IL中完全沒有區別。
第一示例 - 單獨Dim
語句
Dim something As String = "Hello"
Dim somethingElse As String = "World"
Dim putittogether As String = something & " " & somethingElse
編譯爲:
.method public static void Main() cil managed
{
.entrypoint
.custom instance void [mscorlib]System.STAThreadAttribute::.ctor() = (01 00 00 00)
// Code size 28 (0x1c)
.maxstack 3
.locals init ([0] string putittogether,
[1] string something,
[2] string somethingElse)
IL_0000: nop
IL_0001: ldstr "Hello"
IL_0006: stloc.1
IL_0007: ldstr "World"
IL_000c: stloc.2
IL_000d: ldloc.1
IL_000e: ldstr " "
IL_0013: ldloc.2
IL_0014: call string [mscorlib]System.String::Concat(string,
string,
string)
IL_0019: stloc.0
IL_001a: nop
IL_001b: ret
} // end of method Module1::Main
第二示例 - 所有一行
Dim something As String = "Hello",
somethingElse As String = "World",
putittogether As String = something & " " & somethingElse
編譯爲:
.method public static void Main() cil managed
{
.entrypoint
.custom instance void [mscorlib]System.STAThreadAttribute::.ctor() = (01 00 00 00)
// Code size 28 (0x1c)
.maxstack 3
.locals init ([0] string putittogether,
[1] string something,
[2] string somethingElse)
IL_0000: nop
IL_0001: ldstr "Hello"
IL_0006: stloc.1
IL_0007: ldstr "World"
IL_000c: stloc.2
IL_000d: ldloc.1
IL_000e: ldstr " "
IL_0013: ldloc.2
IL_0014: call string [mscorlib]System.String::Concat(string,
string,
string)
IL_0019: stloc.0
IL_001a: nop
IL_001b: ret
} // end of method Module1::Main
來源
2015-07-13 05:55:58
SSS
沒什麼。只是一種風格選擇。 – SSS
@SSS謝謝。不能更簡單。 – user1447679