Javatpoint Logo
Javatpoint Logo

C# Null Propagator

C# Null Propagator is an operator. It is used to check null value in an object reference chain. This operator is a combination of two symbols, question mark (?) and comma (,).

In C# code, if we call a method or property by using null object, compiler throws System.NullReferenceException exception. We receive this exception if we don't check for null in our code.

To avoid this exception, we can use null propagator operator.

In the following example, we are checking for null reference, by using if block, before calling a method.

C# Example without using Null Propagator

Output

Rahul Kumar

In the following example, we are using Null Propagator Operator to check null reference.

C# Example with Null Propagator Operator

Output

PETER
PETER@ABC.COM
Name is empty
Email is empty





Please Share

facebook twitter google plus pinterest

Learn Latest Tutorials


Preparation


B.Tech / MCA