Skip to content

Instantly share code, notes, and snippets.

@mhkoca
Created September 23, 2019 19:59
Show Gist options
  • Save mhkoca/7cfdf2d8652691cae42d050a347d54db to your computer and use it in GitHub Desktop.
Save mhkoca/7cfdf2d8652691cae42d050a347d54db to your computer and use it in GitHub Desktop.
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