using System.Threading.Tasks;
private readonly T _startValue;
_startValue = startValue ?? throw new ArgumentNullException(nameof(startValue), "Start value cannot be null.");
public int DoCalc(object arg1, T arg2)
throw new ArgumentException("arg1 must be an integer.");
if (arg2 is not IConvertible)
throw new ArgumentException("arg2 must be convertible to an integer.");
int result = (int)arg1 + Convert.ToInt32(arg2) / Convert.ToInt32(_startValue);
public static int HigherOrderCalculation(Func<int, int, int> func, int one, int two)
throw new ArgumentNullException(nameof(func), "Function cannot be null.");
public void LogToConsole(string message)
if (string.IsNullOrEmpty(message))
throw new ArgumentException("Message cannot be null or empty.", nameof(message));
Console.WriteLine(message);
public async Task LogToFileAsync(string message)
if (string.IsNullOrEmpty(message))
throw new ArgumentException("Message cannot be null or empty.", nameof(message));
string fileName = $"logfile{DateTime.Now:yyyy-MM-dd}.log";
await File.AppendAllTextAsync(fileName, $"{message}{Environment.NewLine}");
static async Task Main(string[] args)
var foo = new Foo<double>(1.5d);
foo.LogToConsole("Hello World!");
await foo.LogToFileAsync("Hello World!");
var result1 = foo.DoCalc(1, 2.0);
Console.WriteLine($"DoCalc Result: {result1}");
var result2 = Foo<double>.HigherOrderCalculation((x, y) => x + y, 3, 4);
Console.WriteLine($"HigherOrderCalculation Result: {result2}");