How can I add 2 object type lists? C #

0

I have a question about the sum of values in 2 lists, as follows

list1: (taking into account that the values are "name", "type", "quantity") {a, b, 23} {c, d, 2} {e, f, 5} {g, h, 10}

list2: (taking into account that the values are "name", "type", "quantity") {i, j, 1} {k, l, 2} {c, d, 8} * {m, n, 15} {e, f, 80} * {o, p, 46} {g, h, 80} * {q, r, 56} {s, t, 13}

the data I am saving in a new list, which in theory should be the following

list3 (or resulting): (taking into account that the values are "name", "type", "quantity") {a, b, 23} {i, j, 1} {k, l, 2} {c, d, 10} * {m, n, 15} {e, f, 85} * {o, p, 46} {g, h, 90} * {q, r, 56} {s, t, 13}

For example, the data of both the first and the second are added to the new list by adding the data that have coincidence, the others that do not have a coincidence, it is only added to the new one.

at the moment I have this part are taken out of sql

List<BSLBalance> lista = new List<BSLBalance>();
     foreach (var item in ListadoCalculoVentasInventario)
                    {
                        bool has1 = ListadoPedidos.Any(cus => cus.nombre == item.nombre.ToString() && cus.tipo == item.tipo.ToString());
                        if (has1 == true)
                        {
                            foreach (var i in ListadoPedidos)
                            {
                                if (item.nombre == i.nombre && item.tipo == i.tipo)
                                {
                                    BSLBalance obj = new BSLBalance();
                                    obj.nombre = item.nombre;
                                    obj.tipo = item.tipo;
                                    int a = int.Parse(item.cantidad.ToString());
                                    int b = int.Parse(i.cantidad.ToString());
                                    obj.cantidad = a + b;
                                    lista.Add(obj);
                                }
                            }
                        }
                        else
                        {
                            BSLBalance obj = new BSLBalance();
                            obj.nombre = item.nombre;
                            obj.tipo = item.tipo;
                            int a = int.Parse(item.cantidad.ToString());
                            obj.cantidad = a;
                            lista.Add(obj);
                        }
                    }
    
asked by Alvaro Mauricio Angulo Riquelm 21.10.2018 в 18:35
source

0 answers