Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to structure code to run the same service for multiple objects?

Tags:

c#

I have a number of instances of the following object:

public class Brief{
   public int ID {get; set;}
   public DateTime StartDate {get; set;}
   public DateTime EndDate {get; set;}
} 

I want to run the same console service for all these instances. the service essentially uses the ID property and the dates property to search in a database and return the related records for that particular Bried ID.

my question is what is the best approach to structure my code.

should I create a single class with a List and do a foreach on that list and run the appropriate method or should I create a different instance for each of the objects and then run the services.

like image 864
Farhad-Taran Avatar asked May 29 '26 16:05

Farhad-Taran


1 Answers

I'd go with List. Iterate over each one and fire off the method to do your search in a separate thread. That way all 3 searches are performing at the same time.

like image 176
ganders Avatar answered May 31 '26 06:05

ganders



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!