List of int no delegate Func is not working

1

I'm studying something and I came across the following problem. I create a list of 7 elements and treat it within a Func < > it works, but if I increase the items in the list, then my method does not work as it should. That's right: This is the code that works:

List<int> lista = new List<int> { 1, 2, 3, 4, 5, 6, 7 };

            Func<List<int>, int, bool> f = (itens, item) =>
            {
                if (itens != null && itens.Count > 6)
                {
                    int soma = 0;
                    itens.ForEach(it => soma += it + item);
                    return soma % 2 == 0;
                }
                return false;
            };

            var i = from item in lista
                    where f(lista, item)
                    select item;

            i.ToList().ForEach(ite => listBox1.Items.Add(ite));

But if I change the list by putting two more items or one and leaving Count > 6 or change it, even then the code does not work. The result in the listbox should be only even numbers. Below does not work, comes the odd digits and does not pause as I would like. What should I do to make it work? If I put the digit "0", it does not fill anything in the listbox. I just want to understand.

List<int> lista = new List<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 };

            Func<List<int>, int, bool> f = (itens, item) =>
            {
                if (itens != null && itens.Count > 7)
                {
                    int soma = 0;
                    itens.ForEach(it => soma += it + item);
                    return soma % 2 == 0;
                }
                return false;
            };

            var i = from item in lista
                    where f(lista, item)
                    select item;

            i.ToList().ForEach(ite => listBox1.Items.Add(ite));
    
asked by anonymous 02.06.2017 / 16:32

0 answers