Home > Articles > Programming > C#

  • Print
  • + Share This
From the author of

From the author of

Control Structures

A C# switch statement can accept integral, enum, or string values. Java accepts only integral values and definitely doesn't look like this C# switch statement:

   string bar = "Zulu";

   switch (bar) 
   {
     case "Alpha":
        // do something
        break;
     case "Beta":
        // do something
        break;
     case "Charlie":
        // do something
        break;
     default:
        break;
   }

Borrowed from Visual Basic, the C# foreach loop provides fast-forward read-only iteration through an array or collection class. You won't see the following code in Java:

   decimal[] foo = new decimal[] { 1.2m, 3.4m, 5.6m };

   foreach (decimal amount in foo) 
   {
     Console.WriteLine(" " + amount);
   }
  • + Share This
  • 🔖 Save To Your Account