this question has answer here:
which better return null or empty object?
var entity = getfromdb(); if (entity != null) { var price = entity.price != null ? pricedecorator.decorate(entity.price) : null; } public class pricedecorator { public static string decorate(decimal? price) { if (price == null || price == 0) return string.empty; return string.format(cultureinfo.currentculture , "{0:c}", price); } } in above code, return null , return sting.empty, don't know return indicate 'no data'.
any advice?
thanks in advance
it depends:
when return
string.emptyon property of object, means entity exist, object doesn't have property or property in fact string no characters.when return
nullinstead ofstring.emptymeans the entry/entity doesn't exists, in other words, there no data
Comments
Post a Comment