Home   Cover Cover Cover Cover
 

switch-Anweisung

../../solutions/2/Switch.cs
using System;

class Test {
  
  static int DaysOf(int month) {
    int days;
    switch (month) {
      case 1: case 3: case 5: case 7: case 8: case 10: case 12:
        days = 31; break;
      case 4: case 6: case 9: case 11:
        days = 30; break;
      case 2:
        days = 28; break;
      default:
        days = 0; break;
    }
    return days;
  }
  
  static int DaysOf1(string month) {
    int days;
    switch (month) {
      case "Jan": case "Mar": case "May": case "Jul": case "Aug": case "Oct": case "Dec":
        days = 31; break;
      case "Apr": case "Jun": case "Sep": case "Nov":
        days = 30; break;
      case "Feb":
        days = 28; break;
      default:
        days = 0; break;
    }
    return days;
  }
  
  public static void Main() {
    Console.WriteLine(DaysOf(7));
    Console.WriteLine(DaysOf1("Oct"));
  }
}