Switch on day of the week - CSharp Language Basics

CSharp examples for Language Basics:switch

Description

Switch on day of the week

Demo Code

using System;//from w w w. j av a2  s  . com
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
{
   static void Main(string[] args)
   {
      // Input
      Console.Write("Enter a date: ");
      string input = Console.ReadLine();
      DateTime enteredDate = Convert.ToDateTime(input);
      // Finding day of week (in enumeration)
      DayOfWeek dayOfWeek = enteredDate.DayOfWeek;
      // Spanish texts
      string spanish = "";
      switch (dayOfWeek)
      {
         case DayOfWeek.Monday:
             spanish = "Lunes";
             break;
         case DayOfWeek.Tuesday:
             spanish = "Martes";
             break;
         case DayOfWeek.Wednesday:
             spanish = "Miercoles";
             break;
         case DayOfWeek.Thursday:
             spanish = "Jueves";
             break;
         case DayOfWeek.Friday:
             spanish = "Viernes";
             break;
         case DayOfWeek.Saturday:
             spanish = "Sebado";
             break;
         case DayOfWeek.Sunday:
             spanish = "Domingo";
             break;
      }
   }
}

Related Tutorials