Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Comparing strings in 2 list using Linq

Tags:

c#

list

linq

I need to compare to list with strings, and find whitch elements that are similar. ie.

List<string> listA = {"ProfileHeight", "ProfileWidth", "WebThickness"}
List<string> listB ={"ProfileHeightVisibility", "ProfileWidthVisibility", "WebThicknessVisibility", "FlangeThicknessVisibility", "DepthVisibility"}

I was wondering if it is possible to use Linq. I want the result to be a list with the elements from ListB that have a name similar to the strings in listA. Where the statemant i.e. "ProfileHeightVisibility.Contains("ProfileHeight") = true

like image 480
user2590683 Avatar asked Feb 07 '26 14:02

user2590683


1 Answers

You mean you want items in listB where it contains any of the elements in listA?

listB.Where(b => listA.Any(a => b.Contains(a))
like image 176
lc. Avatar answered Feb 09 '26 07:02

lc.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!