readonly

A modifier, in languages such as C# and TypeScript, that lets a field or property be assigned only when it is initialised, never afterwards.

In more detail

It protects values that should not change after construction, such as injected dependencies. It restricts reassignment only; an object held in a readonly field can still change its own contents.

Examples

private readonly IProductRepository _repository;
readonly id: string;
type Point = readonly [number, number];

Related terms

Taught in

References