Skip to content

Instantly share code, notes, and snippets.

@ForNeVeR
Last active July 30, 2020 07:31
Show Gist options
  • Select an option

  • Save ForNeVeR/7f94bbe02b9b1a6de0031fa39481ccf9 to your computer and use it in GitHub Desktop.

Select an option

Save ForNeVeR/7f94bbe02b9b1a6de0031fa39481ccf9 to your computer and use it in GitHub Desktop.

Revisions

  1. ForNeVeR revised this gist Jul 30, 2020. No changes.
  2. ForNeVeR created this gist Jun 12, 2020.
    37 changes: 37 additions & 0 deletions InitializerOrder.cs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,37 @@
    using System;

    namespace ConsoleApp5
    {
    class Base
    {
    private int _baseField = PrintAndReturnLength("Base class field init");
    protected Base()
    {
    Console.WriteLine("Base ctor");
    }

    protected static int PrintAndReturnLength(string message)
    {
    Console.WriteLine(message);
    return message.Length;
    }
    }

    internal class Derived : Base
    {
    private int _derivedField = PrintAndReturnLength("Derived class field init");

    public Derived()
    {
    Console.WriteLine("Derived ctor");
    }
    }

    class Program
    {
    static void Main(string[] args)
    {
    var d = new Derived();
    }
    }
    }
    6 changes: 6 additions & 0 deletions Output.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    ```
    Derived class field init
    Base class field init
    Base ctor
    Derived ctor
    ```