Advertisement
Guest User

Switch/Conditional in C#

a guest
Aug 30th, 2012
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 2.59 KB | None | 0 0
  1. using System;
  2. using System.Text;
  3.  
  4. namespace foo
  5. {
  6.         class Program
  7.         {
  8.                 static void Main(string[] args)
  9.                 {
  10.                         int i = 0;
  11.  
  12.                         switch(i) {
  13.                                 case 1:
  14.                                         Console.WriteLine("One");
  15.                                         break;
  16.                         }
  17.  
  18.                         switch(i) {
  19.                                 case 1:
  20.                                         Console.WriteLine("One");
  21.                                         break;
  22.                                 case 2:
  23.                                         Console.WriteLine("Two");
  24.                                         break;
  25.                                 case 3:
  26.                                         Console.WriteLine("Three");
  27.                                         break;
  28.                                 case 4:
  29.                                         Console.WriteLine("Four");
  30.                                         break;
  31.                         }
  32.                 }
  33.         }
  34. }
  35.  
  36.  
  37. .method private hidebysig static void  Main(string[] args) cil managed
  38. {
  39.   .entrypoint
  40.   // Code size       105 (0x69)
  41.   .maxstack  2
  42.   .locals init (int32 V_0,
  43.            int32 V_1)
  44.   IL_0000:  nop
  45.   IL_0001:  ldc.i4.0
  46.   IL_0002:  stloc.0
  47.   IL_0003:  ldloc.0
  48.   IL_0004:  stloc.1
  49.   IL_0005:  ldloc.1
  50.   IL_0006:  ldc.i4.1
  51.   IL_0007:  beq.s      IL_000b
  52.   IL_0009:  br.s       IL_0018
  53.   IL_000b:  ldstr      "One"
  54.   IL_0010:  call       void [mscorlib]System.Console::WriteLine(string)
  55.   IL_0015:  nop
  56.   IL_0016:  br.s       IL_0018
  57.   IL_0018:  ldloc.0
  58.   IL_0019:  stloc.1
  59.   IL_001a:  ldloc.1
  60.   IL_001b:  ldc.i4.1
  61.   IL_001c:  sub
  62.   IL_001d:  switch     (
  63.                         IL_0034,
  64.                         IL_0041,
  65.                         IL_004e,
  66.                         IL_005b)
  67.   IL_0032:  br.s       IL_0068
  68.   IL_0034:  ldstr      "One"
  69.   IL_0039:  call       void [mscorlib]System.Console::WriteLine(string)
  70.   IL_003e:  nop
  71.   IL_003f:  br.s       IL_0068
  72.   IL_0041:  ldstr      "Two"
  73.   IL_0046:  call       void [mscorlib]System.Console::WriteLine(string)
  74.   IL_004b:  nop
  75.   IL_004c:  br.s       IL_0068
  76.   IL_004e:  ldstr      "Three"
  77.   IL_0053:  call       void [mscorlib]System.Console::WriteLine(string)
  78.   IL_0058:  nop
  79.   IL_0059:  br.s       IL_0068
  80.   IL_005b:  ldstr      "Four"
  81.   IL_0060:  call       void [mscorlib]System.Console::WriteLine(string)
  82.   IL_0065:  nop
  83.   IL_0066:  br.s       IL_0068
  84.   IL_0068:  ret
  85. } // end of method Program::Main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement