ahdung
ahdung

Reputation: 409

A strange question about Null-conditional?

env: VS2017 v15.9.24, .net framework 2.0 c# console project.

this is a very simple console project, no any reference, all codes are in program.cs:

namespace ConsoleApp1
{
    class Program
    {
        static void Main()
        {
            var b = new BClass { Prop = new object() };
            new AClass(b);
        }
    }

    public class AClass
    {
        BClass bClass;

        public AClass(BClass b)
        {
            bClass = b;

            var a1 = bClass;       // not null
            var a2 = bClass.Prop;  // not null
            var a3 = b?.Prop;      // not null
            var a4 = bClass?.Prop; // null, WHY???

            ; // set break point to here
        }
    }

    public class BClass
    {
        public object Prop { get; set; }
    }
}

Upvotes: 1

Views: 123

Answers (1)

Mr Qian
Mr Qian

Reputation: 23715

A strange question about Null-conditional?

Actually, the issue is related to the old net framework 2.0.

We have also tested the same issue as you described. Since we cannot do anything here, I have reported this issue on our DC Forum. See my link.

You can vote it , add any detailed info or comment here if I did not elaborate on the problem.

Anyone who is interested in this issue will preview it and then vote it so that it will attract great attention from Microsoft.

Upvotes: 1

Related Questions