private List<User> _usr ;
public List<User> lst
{
get
{
if (_usr == null)
{
_usr = new List<User>();
}
return _usr;
}
}
|
How can I optimize this code or any shorthand
way to write code of above scenario?
Answer: Yes we can, there are
many way to write code in short to above code.
private List<User> _usr ;
public List<User> lst
{
get
{
_usr = _usr ?? new List<User>();
return _usr;
}
}
|
Or
private List<User> _usr ;
public List<User> lst
{
get{return _usr ?? (new List<User>());}
}
|
No comments:
Post a Comment
Please do not enter any spam link in the comment box.