Xamarin Studio c# null propagating operator

Before filling a bug case about Xamarin Studio I wanted to ask your opinion

public class Class1
{
    public int AProp { get; set; }
}

Considering this simple scenario

Class1 c;
var aProp = c?.AProp;

Shouldn't aProp be inferred as an int? instance as it is in c#-6.0 on Visual Studio 2015+? Because actually it is not, it is inferred as a plain int instead.

Xamarin Studio is not complaining about the operator, but it's not recognizing aProp as a nullable type hence complaining about .HasValue property evaluation for example; not just with the Intellisense but what is worse at compile time

Am I missing something or is it just my IDE?

EDIT : Acutally I just found out I can use it in a null-coalescence check, even if the inferred type is really actually int !! What a mix! XD


I have tried this code in a new Console Application compiled by Visual Studio and it is working fine:

public class Foo
{
    public int Bar { get; set; }
}

static void Main(string[] args)
{

    Foo foo = new Foo(); //same result with Foo foo = null;

    var baz = foo?.Bar;
    if (baz.HasValue) //Expected Error here, but compiles fine
    {
        throw new NotImplementedException();
    }
}

So it is definitive a bug. You should open a new Issue at the Bug tracker of Xamarin Studio.

链接地址: http://www.djcxy.com/p/75160.html

上一篇: 如何使乘法运算符(*)的行为如此短

下一篇: Xamarin Studio c#空传播运算符