c# - nesting three if statements -
i check if condition "_email" met first time , pass result next if statement check , again after that. if _email null, want empty string last check.
here code
private string _email; public string email { { if (string.isnullorempty(_email)) { _email = getemailaddress(); } else if (_email.isemptyornull()) { _email = user.current.preference("email"); } else if (_email.isemptyornull()) { _email = ""; } return _email; } }
i not sure doing wrong. please let me know if need more info.
you need remove else
in code because first if clause condition met executed
and isnullorempty
static method on string
class. use string.isnullorempty
instead of _email.isnullorempty
. (i compiler error when try _email.isnullorempty
)
private string _email; public string email { { if (string.isnullorempty(_email)) { _email = getemailaddress(); } if (string.isnullorempty(_email)) { _email = user.current.preference("email"); } if (string.isnullorempty(_email)) { _email = ""; } return _email; } }
and recommend moving code method called getemail
reduce code in property (it gets ugly in opinion)
Comments
Post a Comment