Use of except in a lambda expression

0

I have this expression and it does not work:

var busca = listaCommiter.Where(l => l.Except(listaFarm.ToString()));  

I have already removed the ToString () and still nothing. listaCommiter and listaFarm are two string lists. I tried with Contains and even the existing files in both lists it says they are different. One list I fill in with GetFileName and the other I Splito a txt file and I mount the list. I think the list of txt, should have strange characters and so the difference, I removed \n and also \r , but there may be something else. Well, how do I compare the two lists with lambda?

    
asked by anonymous 02.03.2016 / 12:03

1 answer

1

I can not understand why you used Where , you do not need it. You only need to use Except to get the expected result.

The Except method documentation says:

  

Produces the difference of two sequences using the standard equality comparer to compare values.

See an example:

var lista = new [] {"nome", "teste", "texto", "outro"};    
var lista2 = new [] {"nome", "teste", "texto", "outro2"};

var excecoes = lista2.Except(lista).ToList();

excecoes.ForEach(WriteLine);

The output will be outro2 .

See in dotNetFiddle

    
02.03.2016 / 12:32