Hello
this program write "Updated" on console. But after reflector - write "Initialization".
using System;
namespace BaseConstructorBug
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine(new A("Updated").Local);
            Console.ReadLine();
        }
    }

    public class A : B
    {
        private string m_local = "Initialization";
        // After reflection only variable definition
        // private string m_local;

        public A(string text)
            : base(text)
        {
            // After reflection variable initialization place here.
            // It's absolutly wrong !!!
            // m_local = "Initialization";
        }

        protected override void SetLocal(string text)
        {
            m_local = text;
        }

        public string Local
        {
            get { return m_local; }
        }
    }

    public abstract class B
    {
        public B(string text)
        {
            SetLocal(text);
        }

        protected abstract void SetLocal(string text);
    }

}

Thanks in advance
x893
0

Add comment

Please sign in to leave a comment.