C# Switch |
---|
int i = 1;switch (i) { case 1: Console.WriteLine('One');break;case 2: Console.WriteLine('Two'); Console.WriteLine('Two'); break; default: Console.WriteLine('Other'); break; } |
Output |
---|
C# Switch |
---|
int i = 2;switch (i) { case 1: Console.WriteLine('One'); break; case 2: Console.WriteLine('Two');Console.WriteLine('Two');break;default: Console.WriteLine('Other'); break; } |
Output |
---|
C# Switch |
---|
int i = 3;switch (i) { case 1: Console.WriteLine('One'); break; case 2: Console.WriteLine('Two'); Console.WriteLine('Two'); break; default: Console.WriteLine('Other');break; } |
Output |
---|
C# Switch |
---|
int i = 1;switch (i) { case 1: Console.WriteLine('One');break;case 2: Console.WriteLine('Two'); break; } |
Output |
---|
C# Switch |
---|
int i = 2;switch (i) { case 1: Console.WriteLine('One'); break; case 2: Console.WriteLine('Two');break; } |
Output |
---|
C# Switch |
---|
int i = 3;switch (i) { case 1: Console.WriteLine('One'); break; case 2: Console.WriteLine('Two'); break; } |
Output |
---|
C# Switch |
---|
int i = 1;switch (i) { case 1: case 2: Console.WriteLine('One or Two');break;default: Console.WriteLine('Other'); break; } |
Output |
---|
C# Switch |
---|
int i = 2;switch (i) { case 1: case 2: Console.WriteLine('One or Two');break;default: Console.WriteLine('Other'); break; } |
Output |
---|
C# Switch |
---|
int i = 3;switch (i) { case 1: case 2: Console.WriteLine('One or Two'); break; default: Console.WriteLine('Other');break; } |
Output |
---|
Enum |
---|
C# Switch |
---|
State state = State.Active;switch (state) { caseState.Active: Console.WriteLine('Active');break;caseState.Inactive: Console.WriteLine('Inactive'); break; default: thrownewException(String.Format('Unknown state: {0}', state)); } |
Output |
---|
Enum |
---|
C# Switch |
---|
State state = State.Inactive;switch (state) { caseState.Active: Console.WriteLine('Active'); break; caseState.Inactive: Console.WriteLine('Inactive');break;default: thrownewException(String.Format('Unknown state: {0}', state)); } |
Output |
---|
Enum |
---|
C# Switch |
---|
State state = (State)3;// maybe new value in futureswitch (state) { caseState.Active: Console.WriteLine('Active'); break; caseState.Inactive: Console.WriteLine('Inactive'); break; default: thrownewException(String.Format('Unknown state: {0}', state)); } |
Output |
---|
C# Switch |
---|
string commandName = 'start';switch (commandName) { case'start': Console.WriteLine('Starting service..');StartService();break;case'stop': Console.WriteLine('Stopping service..'); StopService(); break; default: Console.WriteLine(String.Format('Unknown command: {0}', commandName)); break; } |
Output |
---|
C# Switch |
---|
string commandName = 'stop';switch (commandName) { case'start': Console.WriteLine('Starting service..'); StartService(); break; case'stop': Console.WriteLine('Stopping service..');StopService();break;default: Console.WriteLine(String.Format('Unknown command: {0}', commandName)); break; } |
Output |
---|
C# Switch |
---|
string commandName = 'pause';switch (commandName) { case'start': Console.WriteLine('Starting service..'); StartService(); break; case'stop': Console.WriteLine('Stopping service..'); StopService(); break; default: Console.WriteLine(String.Format('Unknown command: {0}', commandName));break; } |
Output |
---|