How do I pass one object value to another object that needs the same value
For example:
If I have
Contact contact = new Contact();
Scheduler scheduler = new Scheduler();
Call a method to get all of the contact information and now I have contact.id available
The scheduler method which is expecting a personId which is the contact.id
Without doing scheduler.personId = contact.id and passing the value to LoadScheduler what is the proper way? thx
private void LoadSchedule(Scheduler scheduler)
{
...
}
What you are doing isn’t wrong.
Or otherwise you would need better argument for your method..
But then you wouldn’t have all the fields of
Schedulerobject to access. But if that matters..Or even:
Or you can have a proper instance method (or extension method) to load schedule from the scheduler object.
So now you can call just
scheduler.Load()once you have the right instance.. All these aren’t wrong, but depends on which class/layer you need the logics to be in. Without knowing the domain, its hard to say which is the best. Give the job to the right class. To help better, tell us why do you think your approach is wrong in the first place?