我在VS 2013中运行.NET 4.5项目。为什么下面的代码出错?使用C#5.0空传播/空条件运算符时出错
var w = Request.Properties["MS_HttpContext"] as System.Web.HttpContextWrapper;
string IP = w?.Request.UserHostAddress; //fail to compile
我在这个MSDN blog上找到了这段代码。
我在VS 2013中运行.NET 4.5项目。为什么下面的代码出错?使用C#5.0空传播/空条件运算符时出错
var w = Request.Properties["MS_HttpContext"] as System.Web.HttpContextWrapper;
string IP = w?.Request.UserHostAddress; //fail to compile
我在这个MSDN blog上找到了这段代码。
这是仅在将来版本的C#:C#6中可用的新功能。它被称为
null-propagating operator
null-conditional operator。
为了使用C#6,您应该下载CTP of Visual Studio 2015,因为不再支持Visual Studio 2013的扩展(请参阅here)。
它*被称为空传播算子。在C#6规范中,我相信它将被称为空条件运算符。 –
好吧,来自Mads的一张纸条:http://roslyn.codeplex.com/discussions/552378#post1291188超越那个......电子邮件:) –
@Old:需要更多帮助? –
你需要VS 2015与C#6。 – embee