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;
        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


  • New Visual Studio Razor Editor 'Close to Being Ready' for Blazor and Other Projects

    The experimental Razor editor for Visual Studio introduced last summer has been updated and is "close to being ready for normal daily development."

  • Microsoft Updates 'Must Have' Xamarin Community Toolkit

    The Xamarin Community Toolkit provides all kinds of effects, views and helpers to complement mobile app development with Microsoft's recently released, open source, cross-platform Xamarin.Forms 5.

  • JetBrains Unveils Plans for WinForms, WPF and More in Rider .NET IDE

    JetBrains announced plans for Windows Forms, Windows Presentation Foundation (WPF), ASP.NET and more tooling in the next release of its popular Rider IDE for .NET development.

  • Multi-Class Classification Using PyTorch: Model Accuracy

    Dr. James McCaffrey of Microsoft Research continues his four-part series on multi-class classification, designed to predict a value that can be one of three or more possible discrete values, by explaining model accuracy.

Upcoming Events