mercredi 2 octobre 2019

Accessing null value leads to application fail / C#

I'm just looping and appending my properties to a big string:

output.Append(property.GetValue(this).ToString()));

When app braks in that moment property represent a ProductNumber which is a string, value of this is Product object which has value of ProductNumber = null, so I've tried something like this:

output.Append(property.GetValue(this)?.ToString()));

But anyway it breaks..

How could I improve this code to avoid breaking there?

Thanks

Cheers





Aucun commentaire:

Enregistrer un commentaire