c# - "object is null"表达式出错

标签 c# visual-studio-2015 visual-studio-2017 c#-7.0

我有以下代码:

public static class ItemsHelper
{
    public static object product
    {
        get
        {
            return HttpContext.Current.Items["product"];
        }
        set
        {
            HttpContext.Current.Items["product"] = value;
        }
    }
}

然后,在一个函数中,我有以下表达式:

if (ItemsHelper.product is null) return false;

我在 visual studio 2017 中测试,它工作正常,但我在两台运行 visual studio 2015 的不同计算机上测试,它检索到以下错误:

type expected )

有人知道为什么会这样吗?

最佳答案

is null 是 C# 7 的一个特性。您需要一个 C# 7 兼容的编译器来编译您的代码。

Visual Studio 2017 附带一个兼容的,但对于 Visual Studio 2015,您需要更新。检查此问题以获取有关如何更新的说明:How to use c#7 with Visual Studio 2015? .

关于c# - "object is null"表达式出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46786200/

相关文章:

visual-studio - Visual Studio 2017 : QT Add-in

c# - 重写派生类中的 NotMapped 属性

android - 如何在 xamarin.android 中创建新的 keystore ?

amazon-web-services - 使用 Visual Studio 2017 运行 Docker 容器时如何管理 AWS 凭证

unit-testing - Visual Studio 2015 测试资源管理器在更新后不显示任何测试

visual-studio - VS 2015 Team Explorer-Changes 中不一致的双击行为

visual-studio-2017 - Visual Studio 2017 中的单文件生成器更改

c# - ArraySegment - 返回实际段 C#

c# - 您如何使用只读属性模拟类?

c# - 当类不使用 JSON 字符串提供的所有属性时,将 JSON 字符串转换为类