C # Optimization of SWITCH statement

xiaoxiao2021-04-05  311

1 Always constructed by the Switch statement in C # to construct the IF statement when processing the string, because the Switch in the .NET IL also escapes the fate of C.

2 Process the number, and actually the C # compiler to the Switch statement to the string of the string so sweat.

3 First compile the following code:

4 using system;

5 Class Entrypoint 6 {7 private static void main () 8 {9 console.writeline ("Please enter the number: a, b, c, d, e, f"); 10 string szinput = console.readline (); 11 switch (szinput) 12 {13 case "a": 14 console.writeline ("You entered: a"); 15 Break; 16 17 case "B": 18 console.writeline ("You entered: b") 19 Break; 20 21 Case "C": 22 console.writeline ("You entered: C"); 23 Break; 24 25 Case "D": 26 console.writeline ("You entered: a") 27 Break; 28 29 Case "E": 30 console.writeline ("You entered: e"); 31 Break; 32 33 Case "f": 34 console.writeLine ("You entered: f") ; 35 Break; 36 37 Default: 38 console.writeline ("You entered: {0}", Szinput); 39 Break; 40} 41 console.read (); 42} 43} 44 45 Reflector The program is compiled above, the following is the complexed code 46 private static void main () 47 {48 console.writeLine ("/ U8BF7 / U8F93 / U5165 / U5E8F / U53F7: A, B, C, D, E , f "); 49 string text1 = console.readline (); 50 string text2 = text1; 51 if (text2! = null) 52 {53 int Num2; 54 if ( {FEB70444-128D-453C-8E6F- C839E1DC2F51}. $ Method0x6000001-1 == null) 55 {56 Dictionary Dictionary1 = New Dictionary (6); 57 Dictionary1.add ("a", 0); 58 Dictionary1.add ("B", 1); 59 Dictionary1.add ("c", 2) 60 Dictionary1.Add ("D", 3); 61 Dictionary1.Add ("E", 4); 62 Dictionary1.Add ("f", 5); 63 {Feb7044-128D-453C-8E6F- C839E1DC2F51} $ method0x6000001-1 = dictionary1;. 64} 65 if (. {FEB70444-128D-453C-8E6F-C839E1DC2F51} $ method0x6000001-1.TryGetValue (text2, out num2)) 66 {67 switch (num2) 68 {69 case 0: 70 console.writeline ("

转载请注明原文地址:https://www.9cbs.com/read-132196.html

New Post(0)