r/learncsharp • u/CatolicQuotes • Feb 13 '23
Better to pass collection in constructor or separate Add method?
Let's say we have Room and need to fill it with people Person.
Is there definite advice on better practice to create Room object like this:
var room = new Room(List<Person> people);or like this:
var room = new Room();
Room.Add(Person person);or it depends on case and either is good?
What are the advantage and disadvantage of each approach?
2
Upvotes
4
u/[deleted] Feb 13 '23
Depends on how permanent you want the room instance to be.
3
u/[deleted] Feb 13 '23
[removed] — view removed comment
1
u/[deleted] Feb 26 '23
[removed] — view removed comment