2

I am developing a .NET 4.5 project, which will run on Windows 7 machines; however I am developing it on the Windows 10 machine.

What I am having problem with is the fact, that null checking operator ?. has only been introduced with .NET 4.6 (as far as I know).

Even though my project is targetting .NET 4.5, I can still use ?. operator in my code, and VS returns no error. Here is an example of what I mean:

Pre ?. operator code:

            var sAdditionalNode  = xNodes.Current.SelectSingleNode("Details/SomeDetails", xNameSpace);
            if (sAdditionalNode!=null)
            {
                var sAdditionalDetails = sAdditionalNode.Value;
            }

After ?. operator has been implemented

var sAdditionalDetails = xNodes.Current.SelectSingleNode("Details/SomeDetails", xNameSpace)?.Value;

Am I correct when I believe, that even though currently I have no problem using ?. operator in my code; once I deploy my project under the Windows 7 (with .NET 4.5), I will suddenly start having problems?

Robert J.
  • 2,631
  • 8
  • 32
  • 59
  • 1
    Null propagation operator introduced in C# 6.0. It doesn't depend on .NET version. – Hamlet Hakobyan Jan 31 '16 at 12:49
  • I don't quite understand this, I though that C# 6.0 is depended on the .NET version. So you are saying, that I can freely use null operator in my code? – Robert J. Jan 31 '16 at 12:50
  • Setting C# 5.0 compliance is a [separate setting](http://stackoverflow.com/questions/30461640/how-do-i-disable-c-sharp-6-support-in-visual-studio-2015) from the framework. – crokusek Dec 26 '16 at 00:03

1 Answers1

2

Roslyn can actually compile the code for older versions of .net framework. You should be safe with elvis operator. Compatibility problems should only occur when you are using new types from target .net framework.

mano
  • 136
  • 3