Is it acceptable to declare new objects (and return them) from within the same object, as in the example below?
Or, is it better to move it to some kind of handler
class?
public class Person
{
public string Name { get; set; }
public int Age { get; set; }
//Gets a list of persons
public List<Person> GetPersons()
{
List<Person> _listPersons = new List<Person>();
Person _person = new Person();
_person.Name = "FooFii";
_person.Age = 50;
_listPersons.Add(_person);
return _listPersons;
}
}
GetPersons
be static or not a member of Person. Currently you need aPerson
to callGetPersons
Object
class (the root of the class hierarchy) explicitly mandates aclone()
method which is intended to provide a copy of the object.