【问题标题】:Error when using the null-propagating / null-conditional operator使用空传播/空条件运算符时出错
【发布时间】:2015-06-13 14:37:49
【问题描述】:

我在 VS 2013 中运行 .NET 4.5 项目。为什么下面的代码会出错?

var w = Request.Properties["MS_HttpContext"] as System.Web.HttpContextWrapper;
string IP = w?.Request.UserHostAddress; //fail to compile

我在MSDN blog 上找到了这段代码。

【问题讨论】:

    标签: c# c#-6.0 null-propagation-operator


    【解决方案1】:

    这是 C# 6 和更新版本中提供的新功能。它被称为null-conditional operator。

    要使用 C# 6,您应该下载 Visual Studio 2015 或更新版本,因为不再支持 Visual Studio 2013 的扩展(请参阅here)。

    【讨论】:

    猜你喜欢
    • 2015-02-26
    • 2017-08-25
    • 1970-01-01
    • 1970-01-01
    • 2017-12-01
    • 1970-01-01
    • 1970-01-01
    • 2016-07-13
    相关资源
    最近更新 更多