No, not really.
In your code, when you check for if (Objs == null)
- you are effectively using the get method in which you are currently in. So Objs { get; }
calls itself, and that's why it's always recursive.
Remember that auto properties (get; set;
) is really just a shorthand for having a backing field and separate get and set methods. Without that magic, your code would look like this:
private List<Obj> _objs;
public List<Obj> GetObjs() { return _objs; }
public void SetObjs(List<Objs> objs) { _objs = objs; }
What you are really implementing in your post is this - notice how GetObjs() is calling itself multiple times. So for every time it calls itself, it will eventually lead to it calling itself again. And again, and again.:
public List<Obj> GetObjs() {
if (GetObjs() == null)
{
SetObjs(new List<Obj>());
}
if (GetObjs().Count < 1)
{
GetObjs().Add(new Obj());
}
return GetObjs();
}