readonly

A field modifier allowing assignment only in the declaration or a constructor.

What does readonly do in C#?

readonly — A field modifier allowing assignment only in the declaration or a constructor.

class Store
{
    readonly string name;

    Store(string name)
    {
        this.name = name;
    }
}

Level: Apprentice · More C# terms at this level

Updated

In other subjects