If I have a class like below, how would I create the function nullToEmptyString()?
If object is DBNull.Value then return an empty string, otherwise return the value. The function should work on every object in person.
public class Person
{
public object surname { get; set; }
public object lastname { get; set; }
public object zip_code { get; set; }
public object tele { get; set; }
}
I retrieve a list of persons from the DB and I want to print the value, if it has a value, otherwise an empty string.
foreach (var person in listFromDB)
{
person.surname.nullToEmptyString()
person.lastname.nullToEmptyString()
}
EDIT
In short, this function should work like the .ToString() function but would also be able to handle DBNull values.