我有以下相當(dāng)簡(jiǎn)單的 switch 語(yǔ)句。// 較早的字符串 fullPath = GetFullPath(); 字符串類型 = GetEntityType();switch (type.ToLower()) { case "tables": tables.Add(fullPath); break; case "views": views.Add(fullPath); break; case "functions": functions.Add(fullPath); break; case "storedprocs": storedprocs.Add(fullPath); break; case "data": data.Add(fullPath); break; case "layouts": layouts.Add(fullPath); break; case "scripts": scripts.Add(fullPath); break; default: Console.WriteLine($"What is this: {type}"); break;}當(dāng)我使用 Reflector 反編譯生成的二進(jìn)制文件時(shí),switch(string)它已更改為 ComputeStringHash,然后在每個(gè) case 語(yǔ)句中,它通過if語(yǔ)句檢查值。聽起來它正在做雙倍的工作。 string s = str2.ToLower(); switch (<PrivateImplementationDetails>.ComputeStringHash(s)) { case 0x20890fc4: if (s == "tables") { break; } goto Label_0218; case 0x454a414e: if (s == "functions") { goto Label_01DE; } goto Label_0218; case 0x4facf6d1: if (s == "views") { goto Label_01D3; } goto Label_0218; case 0xcdfe2cb3: if (s == "storedprocs") { goto Label_01E9; } goto Label_0218; case 0xd872e2a5: if (s == "data") { goto Label_01F4; } goto Label_0218; case 0x9b4a129b: if (s == "scripts") { goto Label_020C; } goto Label_0218; case 0xba971064: if (s == "layouts") { goto Label_0200; } goto Label_0218; default: goto Label_0218; }
為什么編譯器會(huì)在 switch 中添加語(yǔ)句?
BIG陽(yáng)
2022-06-18 17:37:51