Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bidimensional array C#

I want to have two arrays:

  1. supplierList - that contains the int ID of each supplier element that i have in my graph and then for each supplier that i have in this list a separate list
  2. clientList - that contains the list of the clients of that determinate supplier.

so i want for example to have :

[12,13,53,165,76] that are the IDs of the suppliers and supplierList[12] the clientList of the supplier 12.

I tried with that:

    public void calculateMetrics (MDG graph)
    {
        ArrayList supplierList = new ArrayList();
        ArrayList clientList = new ArrayList();

        foreach (EA.Package package in modelRepository.Models)
        {
            foreach (EA.Package pack in package.Packages)
            {
                foreach (EA.Connector link in pack.Connectors)
                {
                    int supplier = link.SupplierID;
                    int client = link.ClientID;

                    for(int i=0; i<supplierList.Count; i++)
                    { 
                        if (supplier.Equals(supplierList[i]))
                        {
                            **((ArrayList)clientList((ArrayList)supplierList[i]).Add(client);**



                    supplierList.Add(clientList);

But without a surprise it doesn't work, but i don't know how to do it.

like image 652
Defi Avatar asked Apr 09 '26 08:04

Defi


1 Answers

Why not create a Supplier Object that contains a List of Client IDs as a member variable? This way you are only involving one List to iterate through directly and it will clean up your code.

More specifically:

Supplier object (Class) - Has ID (int), Client (Object)

Client object (Class) - Has ID, perhaps other properties.

Look up the syntax for object creation; you will find in an object-oriented environment, creating objects can really help out!

like image 97
BlackVegetable Avatar answered Apr 10 '26 22:04

BlackVegetable



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!