Why initializing auto implemented property works in .net 2.0?

My code with target framework .net 2.0 complies and initializes the auto implemented property in following code where as we can initialize auto implemented properties from C#6 which came in .net version 4.6.

    class Program
    {
        static void Main()
        {
            Circle cr = new Circle();

            Console.WriteLine("Radius=" + cr.Radius);

        }
    }

    class Circle
    {
        public double Radius
        {
            get;
            set;
        } = 12.45;  // Initializing Auto Implemented property
    }

Upvotes: 3

Views: 177

Answers (1)

Patrick Hofman
Patrick Hofman

Reputation: 156978

Auto-implemented properties have been introduced with C# 3. C# 3 works with the .NET Framework version 2. In C# 6 you can assign a value while declaring auto-implemented properties. This is a language feature, not a CLR feature.

So all of the above is fine: the language does support .NET 2, and the language supports the language feature. There is no reason it shouldn't work.

Upvotes: 5

Related Questions