Created
September 23, 2019 19:59
-
-
Save mhkoca/7cfdf2d8652691cae42d050a347d54db to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Collections.Generic; | |
namespace DictionaryTraining | |
{ | |
public class Program | |
{ | |
static Dictionary<ReportType, Func<int, string>> dictReports = new Dictionary<ReportType, Func<int, string>>(); | |
static void Main(string[] args) | |
{ | |
Reporter reporter = new Reporter(); | |
dictReports.Add(ReportType.Daily, new Func<int, string>(reporter.GetDailyReport)); | |
dictReports.Add(ReportType.Weekly, new Func<int, string>(reporter.GetWeeklyReport)); | |
dictReports.Add(ReportType.Monthly, new Func<int, string>(reporter.GetMonthlyReport)); | |
dictReports.Add(ReportType.Annual, new Func<int, string>(reporter.GetAnnualReport)); | |
dictReports[ReportType.Daily](60); | |
Console.ReadLine(); | |
} | |
} | |
public class Reporter | |
{ | |
public string GetDailyReport(int dayOfYear) | |
{ | |
Console.WriteLine("Daily report is preparing..."); | |
return "report of day: " + dayOfYear; | |
} | |
public string GetWeeklyReport(int weekOfYear) | |
{ | |
Console.WriteLine("Weekly report is preparing..."); | |
return "report of week: " + weekOfYear; | |
} | |
public string GetMonthlyReport(int monthOfYear) | |
{ | |
Console.WriteLine("Monthly report is preparing..."); | |
return "report of month: " + monthOfYear; | |
} | |
public string GetAnnualReport(int year) | |
{ | |
Console.WriteLine("Annual report is preparing..."); | |
return "report of year: " + year; | |
} | |
} | |
enum ReportType | |
{ | |
Daily, | |
Weekly, | |
Monthly, | |
Annual | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment