Tip: Aim to write code that is clear enough to understand without requiring extensive comments. Use comments to explain the "why" behind decisions rather than the "what" of the code.
public double CalculateDiscount(double originalPrice, double discountRate)
{
// Ensure the discount rate is between 0 and 1
if (discountRate < 0 || discountRate > 1)
{
throw new ArgumentOutOfRangeException(nameof(discountRate), "Discount rate must be between 0 and 1");
}
return originalPrice * (1 - discountRate);
}