Anshuman Jasrotia Anshuman Jasrotia - 1 year ago 67
C# Question

What does object?.Property mean in c#

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#

Answer Source

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

Used to test for null before performing a 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

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download