C# Concept - Computed properties
Overview
Section titled βOverviewβComputed properties are a property design pattern, not a standalone C# language release feature. They are built with ordinary property getters.
Introduced In
Section titled βIntroduced InβThis pattern has been possible since C# 1.0 (2002).
Example
Section titled βExampleβ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.