linq - How to remove list element? -
i have 2 lists below.
list<string> apple= new list<string>(); apple.add("a"); apple.add("b"); list<string> ball= new list<string>(); ball.add("a,b"); ball.add("b,c"); ball.add("c,a");
now want remove elements ball
list of there substrings of elements in apple
list. if "a" occurs in ball
list element, have remove listelements ball
list.
my expected output of ball list should (b,c).
here quick linqpad
var apple= new list<string>(); apple.add("a"); var ball= new list<string>(); ball.add("a,b"); ball.add("b,c"); ball.add("c,a"); ball.where(b=>apple.any(b.contains)) .tolist() //create duplicate, lists have foreach .foreach(b=>ball.remove(b)); ball.dump();
output is:
b,c
Comments
Post a Comment