Syntax For Switch with Example In C#.Net and VB.Net

Syntax for switch statement with example in c#.net and VB.net. Here i have shown the sample code to show detail as per passed value in switch case.
In today's article i will show you a syntax for switch statement in C#.net. As all we know C# and vb.net have provided multiple ways to apply if condition in to execute the code. But Switch statement one of the most optimized and fast and clear way to write the condition. 

In this I will show you switch statement syntax with example. 

C#.Net

int caseValue = 1;
switch (caseValue) { 
    case 1:
        Console.WriteLine("case 1");
        break;
    case 2:
        Console.WriteLine("case 2");
        break;
    default:
        Console.WriteLine("default case");
        break;
} 

VB.Net

Dim caseValue As Integer = 1
Select Case caseValue
    Case 1
        Console.WriteLine("case 1")
    Case 2
        Console.WriteLine("case 2")
    Case Else
        Console.WriteLine("default case")
End Select 
In above code I have taken a variable of integer type.  Now as per variable value we are displaying the message. Now run the code to check the output.

Switch Case Value

Post a Comment