5

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

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

我在这个MSDN 博客上找到了这段代码。

4

1 回答 1

17

这是 C# 6 和更新版本中提供的新功能。它被称为空条件运算符

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

于 2015-04-08T14:48:47.250 回答