Lambda Properties: Listing 1

Calculating a discount rate.

public class Foo
{
  public Func<Customer, decimal> GetDiscountRate { get; set; }
 
  public Foo()
  {
    this.GetDiscountRate = DefaultDiscountRate;
  }
 
  private decimal DefaultDiscountRate(Customer customer)
  {
    switch (customer.CustomerType)

    {
      case CustomerType.Probation:
        return 0.02m;
 
      case CustomerType.Normal:
        return 0.045m;
 
      case CustomerType.Preferred:
        return 0.07m;
 
      default:
        throw
        new ArgumentException("Unsupported CustomerType");
    }
  }
}

About the Author

Patrick Steele is a senior .NET developer with Billhighway in Troy, Mich. A recognized expert on the Microsoft .NET Framework, he’s a former Microsoft MVP award winner and a presenter at conferences and user group meetings.

comments powered by Disqus

Featured

Subscribe on YouTube