I am trying to create an ArrayList from two Lists that have their objects extracted from a database in SQL Server.
This is the code I used to populate the two Lists:
FoodStoreEntities context = new FoodStoreEntities();
List<Supplier> suppliers = context.Suppliers.ToList();
List<Manufacturer> manufacturers = context.Manufacturers.ToList();
This is how I'm trying to add them into an ArrayList:
ArrayList supplierManufacturer = new ArrayList();
foreach (Supplier item in suppliers)
{
supplierManufacturer.Add(item.vendor);
supplierManufacturer.Add(item.supplier_email);
}
foreach (Manufacturer item in manufacturers)
{
supplierManufacturer.Add(item.mfg);
supplierManufacturer.Add(item.mfgDiscount);
}
However, when I try to display the ArrayList, the types doesn't seem to match. I get "no match" when I run the console:
static void Display(ArrayList aryList)
{
foreach (Object obj in aryList)
{
if (ObjectContext.GetObjectType(obj.GetType()) == typeof(Supplier))
{
Supplier supplier = (Supplier)obj;
Console.WriteLine(supplier.vendor + " " + supplier.supplier_email);
}
else if (ObjectContext.GetObjectType(obj.GetType()) == typeof(Manufacturer))
{
Manufacturer manufacturer = (Manufacturer)obj;
Console.WriteLine(manufacturer.mfg + " " + manufacturer.mfgDiscount);
}
else
Console.WriteLine("no match");
}
}
I don't know what's going on and have tried searching for related topics but it's to no avail. Please help. Thanks!