Home > ADO.NET > What is Null Conditional Operator?

What is Null Conditional Operator?

The null conditional operator prevents the execution of a method if the caller object is null.

Explaination:

Whether you are novice or experienced developer you must be familiar with null reference exceptions. You must be tired of writing null checking code to make sure your application handles null references correctly. The null-conditional operator is going to save you from writing lots of null checking code. In this article I am going to explain the usage of null-conditional operator with the help of an example.

if the s.city is blank then we write like as follow

if (s.city != null){

    lblCity.Text = s.city.name;

}

but we can avoid check if condition by using null condition operator as follow

lblCity.Text = s.city?.name;

for more information click here.

 

 

 

 

 

This Article is TAGGED in , . BOOKMARK THE permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">