Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How to do a foreach loop with multiple lists

I am trying to do a foreach loop that runs through 3 lists. Here is what I have currently:

foreach (Button btn in appList && sequenceLsit && FunctionList)
{
    if (btn.FillColor != Color.White) 
    {
        // Do stuff
    }
}

I tried using tuples, but as I understand, they use a separate variable for each list. I need a single variable (btn) for all 3 lists.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

A foreach loop enumerates one list. If you have three separate lists then you need to create one list from them first, which can then be enumerated. The simplest way to do that is the Enumerable.Concat extension method:

foreach (Button btn in appList.Concat(sequenceLsit).Concat(FunctionList))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading