I have a dilemma. The task (reduction) is to remake the next data holder class
class Stuff { public String SomeInfo { get; set; } }
to satisfy the requirement that null is not returned. I can think of two ways to achieve this, and after looking deeply at 15 minutes, I just can't decide which one is preferable.
Designer approach.
class Stuff { public String SomeInfo { get; set; } public Stuff() { SomeInfo = String.Empty; } }
Property Approach.
class Stuff { private String _SomeInfo; public String SomeInfo { get { return _SomeInfo ?? String.Empty; } set { _SomeInfo = value; } } }
Note that creating instances of Stuff can be done using the constructor, as well as initialization, if that matters. As far as I know, there will be no other restrictions (but you know how customer specifications do not always reflect reality).
c # properties
Konrad Viltersten
source share