Fill a listbox with predicatestring

0

I'm studying DDD and WebAPI and as I find it difficult, I'm researching and trying to solve it. Of course, sometimes I come across simple things for some here and I can not solve them right away.

Sometimes I even understand what has to be done, but I do not know how to do it, as is the case now. With Console project, I did, but I switched to a Windows Form and am having this difficulty.

I need to populate a ListBox, as a result of a Foreach lambda resulting from a list of a Predicate. The question is in ForEach, like this:

private void button1_Click(object sender, EventArgs e)
{
    string[] teste = new string[] { "um", "dois", "tres", "quatro", "cinco" };
    Predicate<string> p = objetoTeste => objetoTeste.Length >= 4;

    var i = from items in teste
            where (p(items))
            select (items);

    i.ToList().ForEach(listBox1.Items.Add()**==>> Dúvida aqui**);

    /*foreach (var item in teste)
    {
        listBox1.Items.Add(item);
    }*/
}

The question is how to call ListBox1.Items.Add() and fill it in foreach

    
asked by anonymous 02.06.2017 / 15:20

1 answer

3

So

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

If the parameter of the Add method is of the same type as item (string, in this case) it can still be simpler

i.ToList().ForEach(listBox1.Items.Add);

See working .NET Fiddle.

    
02.06.2017 / 15:26