Error when using the null-propagating / null-conditional operator
Asked Answered
C

1

5

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.

Cathe answered 8/4, 2015 at 14:47 Comment(0)
H
17

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).

Histochemistry answered 8/4, 2015 at 14:48 Comment(2)
Well, a note from Mads: roslyn.codeplex.com/discussions/552378#post1291188 Beyond that... emails :)Clinquant
@Old: need more help?Histochemistry

© 2022 - 2024 — McMap. All rights reserved.