gpt4 book ai didi

c# - 使用 null 传播/null 条件运算符时出错

转载 作者:太空狗 更新时间:2023-10-29 22:09:10 25 4
gpt4 key购买 nike

我在 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# 6 和更新版本中提供的新功能。它被称为 null-conditional operator .

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

关于c# - 使用 null 传播/null 条件运算符时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29518012/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com