Error when using the null-propagating / null-conditional operator

血红的双手。 提交于 2019-12-04 03:28:13

问题


I am running a .NET 4.5 project in VS 2013. Why is the following code in error?

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

I found this code on this MSDN blog.


回答1:


That is a new feature available in C# 6 and newer versions. It is called the null-conditional operator.

In order to use C# 6 you should download Visual Studio 2015 or a newer version, since the extension for Visual Studio 2013 isn't supported any more (see here).



来源:https://stackoverflow.com/questions/29518012/error-when-using-the-null-propagating-null-conditional-operator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!