C# Modifier readonly

Modifier: readonly

As the name suggests, the readonly modifier is used to make a member readonly. The content of the member can only be set either during the initial declaration (A) or in the constructor for the class that uses the member (B).

Example A:

readonly int foo = 5;

Example B:

class Foo {
    readonly int bar;
    Foo()
    {
        bar = 5;
    }
}

 

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s