using System;
namespace Keyword_Enum
{
class Program
{
static void Main(string[] args)
{
//pass enum into a function
Console.WriteLine(WhatToDo(DaysInItalian.Sabato));
Console.WriteLine(WhatToDo(DaysInItalian.Domenica));
//enums are zero-index based, go through 5 days
for (int i = 0; i <= 4; i++)
{
//cast int to enum, then pass the enum into a function
Console.WriteLine(WhatToDo((DaysInItalian)i));
}
Console.Read();
}
static string WhatToDo(DaysInItalian giorni)
{
switch (giorni)
{
case DaysInItalian.Sabato:
return "Lovely day for a guiness.";
case DaysInItalian.Domenica:
return "Walk around the park.";
default:
return "Back to work.";
}
}
}
enum DaysInItalian
{
Lunedi, Martedi, Mercoledi, Giovedi, Venerdi, Sabato, Domenica
}
}
Friday, June 5, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment