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.