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?

3
  • 1
    Null propagation operator introduced in C# 6.0. It doesn't depend on .NET version. Commented Jan 31, 2016 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? Commented Jan 31, 2016 at 12:50
  • Setting C# 5.0 compliance is a separate setting from the framework. Commented Dec 26, 2016 at 0:03

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.