CSharp - Constructor and field initialization order

Introduction

Fields can be initialized with default values in their declaration:

Field initializations occur before the constructor is executed, and in the declaration order of the fields.

Demo

using System;
class MainClass/*from   w  w  w  .ja v  a  2  s  . c o m*/
{
    public static void Main(string[] args)
    {

        new Person();

    }
}

class Person
{
    static int i = 0;
    int a = i++;   // Initialized first
    int b = i++;   // Initialized second

    public Person()
    {
        Console.WriteLine(a);
        Console.WriteLine(b);
        a = i++;   // Initialized first
        b = i++;   // Initialized second
        Console.WriteLine(a);
        Console.WriteLine(b);
    }
}

Result