2

在填写有关 Xamarin Studio 的错误案例之前,我想询问您的意见

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

考虑到这个简单的场景

Class1 c;
var aProp = c?.AProp;

不应该像在 Visual Studio 2015+ 上的 c#-6.0 中那样aProp将其推断为实例吗?int?因为实际上不是,所以被推断为平原int

Xamarin Studio 没有抱怨运算符,但它没有识别aProp为可空类型,因此抱怨.HasValue属性评估;不仅是 Intellisense,而且在编译时更糟糕的是

我错过了什么还是只是我的 IDE?

编辑:实际上我刚刚发现我可以在空合并检查中使用它,即使推断的类型实际上是int!什么混合!XD

4

1 回答 1

1

我已经在 Visual Studio 编译的新控制台应用程序中尝试了此代码,它工作正常:

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();
    }
}

所以这绝对是一个错误。您应该在 Xamarin Studio 的 Bug 跟踪器中打开一个新问题。

于 2017-06-13T14:19:12.883 回答