Thursday, September 8, 2011

trying to understand Func

public ActionResult Index()

{

   Func<Int16, string> convertInteger = TryToGiveGermanNameForSingleDigit;

   Int16 numberOfFingersOnOneHand = 5;

   ViewBag.Message = convertInteger(numberOfFingersOnOneHand);

   return View();

}

   

private static string TryToGiveGermanNameForSingleDigit(Int16 digit)

{

   string valueToHandBack;

   switch(digit)

   {

      case 0:

         valueToHandBack = "null";

         break;

      case 1:

         valueToHandBack = "eins";

         break;

      case 2:

         valueToHandBack = "zwei";

         break;

      case 3:

         valueToHandBack = "drei";

         break;

      case 4:

         valueToHandBack = "vier";

         break;

      case 5:

         valueToHandBack = "fünf";

         break;

      case 6:

         valueToHandBack = "sechs";

         break;

      case 7:

         valueToHandBack = "sieben";

         break;

      case 8:

         valueToHandBack = "acht";

         break;

      case 9:

         valueToHandBack = "neun";

         break;

      default:

         valueToHandBack = "Scheisse!";

         break;

   }

   return valueToHandBack;

}

No comments:

Post a Comment