vendredi 2 avril 2021

How to merge / remove data from lists in C#

I have a large amount of variables that contain lists as of (A,B,C,...) some of these variables contains same items in their respective lists and my goal is to display the similar items in list as an output. I have utilized Intersect for such purposes but considering I have 46 lists in my program Intersecting each list would be time consuming and problematic. So far I have created this:

//I have 46 of these

            var mtl = new List<string>() { "a", "b", "v", "s" };
            var pigm = new List<string>() { "x", "a", "s", "t" };
            var catalas = new List<string>() { "a", "e", "m", "i" };
//if user checks the respective checkbox I will merge the data from alredy checked boxes and store it in a string/var
 private void listOne_CheckedChanged(object sender, EventArgs e)
        {
            if (catalaz.Checked == true)
            {
                //my potential problem
                var result = pigm.Intersect(catalas);
            }
        }

so to summarize I would like a potential efficient way to merge and store the list every time a checkbox is checked greatly appreciate your input on this situation.




Aucun commentaire:

Enregistrer un commentaire