Skip to content

C# Concept - Computed properties

Computed properties are a property design pattern, not a standalone C# language release feature. They are built with ordinary property getters.

This pattern has been possible since C# 1.0 (2002).

public class Rectangle
{
public double Width { get; set; }
public double Height { get; set; }
public double Area => Width * Height;
}
  • Keep computations cheap; cache with a lazy property if the work is expensive.
  • Prefer a method instead of a property when parameters are required or the work is surprising.