Skip to content

Instantly share code, notes, and snippets.

View AhmedTarekHasan's full-sized avatar

Ahmed Tarek Hasan AhmedTarekHasan

View GitHub Profile
using System;
namespace SmallMethods
{
public class Program
{
static void Main(string[] args)
{
Console.WriteLine("Started");
var result1 = GetResultRecursively(50_000, 40_000);
using System;
namespace LargeMethod
{
public class Program
{
static void Main(string[] args)
{
Console.WriteLine("Started");
var result = GetResultRecursively(20_000);
using System;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Running;
namespace Benchmarking
{
public class Program
{
static void Main(string[] args)
{
public class Program
{
static void Main(string[] args)
{
Console.WriteLine(Run());
Console.ReadLine();
}
public static decimal Run()
{
public abstract class TaxCalculator
{
private readonly Func<TaxCalculator, decimal> _calculateDelegate;
protected TaxCalculator()
{
// Generate the function only once and then call it many times.
_calculateDelegate = BuildExpression(this).Compile();
}
public class TaxCalculator1 : TaxCalculator
{
protected override bool CanCalculateExpenses => false;
protected override bool CanCalculateIncomeTax => true;
protected override bool CanCalculateVat => false;
// No logic to apply. Therefore, just return 0.
protected override decimal CalculateExpenses(decimal input)
{
public class Program
{
static void Main(string[] args)
{
Console.WriteLine(Run());
Console.ReadLine();
}
public static decimal Run()
{
public abstract class TaxCalculator
{
public decimal CalculateTaxes()
{
decimal total = 1436;
if (this is ICalculateExpenses expensesCalculator)
{
// This call would be skipped in case of TaxCalculator1
total += expensesCalculator.CalculateExpenses(1436);
public class TaxCalculator1 : TaxCalculator, ICalculateIncomeTax
{
public decimal CalculateIncomeTax(decimal income)
{
return income + 100;
}
}
public class TaxCalculator2 : TaxCalculator, ICalculateExpenses
{
public interface ICalculateExpenses
{
decimal CalculateExpenses(decimal input);
}
public interface ICalculateIncomeTax
{
decimal CalculateIncomeTax(decimal income);
}