CSharp - Type Creation readonly modifier

Introduction

readonly modifier prevents a field from being modified after construction.

A read-only field can be assigned only in declaration or in the type's constructor.

Demo

using System;
class MainClass/*from w  w  w .ja v  a 2 s . c o  m*/
{
    static readonly int v = 5;

    public static void Main(string[] args)
    {

        Console.WriteLine(v);

        new MyClass();

    }
}
class MyClass
{
    readonly int v;

    public MyClass()
    { //constructor
        v = 6;
    }
}

Result

Quiz