I have a List of two different objects i.e.
List<Customer> Customers;
List<Retailer> Retailers;
I have a method which if i pass in the List with the appropriate type separately everything works.
I thought to try Generics to see if i can have one method to do two tasks i.e. Pass in the type of List and it would iterate through the list and get the record and take whatever action necessary.
private T AddRecord<T>(List<T> ListofRecords)
{
foreach (T rec in ListofRecords.Records)
{
Object ob = GetRecord(rec.Id);
}
}
The issue i'm coming across is that rec
(the variable for the foreach
loop) doesnt know what type it is so i cant get to the ID property.
How should i be doing this?