Create a switch statement with only default in CSharp

Description

The following code shows how to create a switch statement with only default.

Example


using System;//  w  w  w . j  a v a 2s.co m

public class MainClass {     
   static void Main()
   {
      for (int x = 1; x < 4; x++)
      {
         switch (x)
         {
            default:
               Console.WriteLine("x is {0} -- In Default case", x);
               break;
         }
      }
   }
}

The code above generates the following result.





















Home »
  C# Tutorial »
    C# Language »




C# Hello World
C# Operators
C# Statements
C# Exception