4

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#

sujith karivelil
  • 27,818
  • 6
  • 51
  • 82
Anshuman Jasrotia
  • 3,079
  • 8
  • 45
  • 78

1 Answers1

16

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

sujith karivelil
  • 27,818
  • 6
  • 51
  • 82