Exclude a list of Strings in a table in C #?


Hello friend I have a problem with a table I have a field called names within this table and I have a list of names which I want to exclude from the table based on the name field. I have the following but it does not work for me.

var DataRows = Tabla.AsEnumerable().Where(item => item["Nombre"].ToString().Distinct().Where(nombre=> ListaNombres.ForEach()))
asked by Aetos2501 26.07.2018 в 19:27

1 answer


You should check if the string list exists in your item item, with Any() , in this case we add a NOT , which would return that if the item exists it does not add it

   var DataRows = Tabla.AsEnumerable().Where(
                    item => !ListaNombres.Any(n => n == item["Nombre"].ToString()));
answered by 26.07.2018 / 19:47