Error when using C # 5.0 operator with zero propagation / null condition

I am running a .NET 4.5 project in VS 2013. Why is the following code an 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 .

+5
source share
1 answer

This is a new feature, available only in a future version of C #: C # 6. It is called an operator carrying a null operator with a null condition .

To use C # 6, you must download Visual Studio 2015 CTP , as the extension for Visual Studio 2013 is no longer supported (see here ).

+17
source

All Articles