5

I recently came across this while going through someone else's code

var name = Product.Buyer?.FirstName + " " + Product.Buyer?.LastName; 

What does this(?.)mean in c#

2
  • (I've tried to find a duplicate, but failed. Not so easy to search for, although I'm sure there are very similar questions.) Commented Sep 15, 2016 at 6:01
  • 3
    Jon Skeet Commented on my question :) . Wow Commented Sep 15, 2016 at 6:09

1 Answer 1

19

The operator ?. is called Null-conditional Operators, which is introduced in C# 6.0.

Used to test for null before performing member access (?.) or index (?[) operation. These operators help you write less code to handle null checks, especially for descending into data structures.

see the documentation and an example here

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.