Click here to Skip to main content
15,885,875 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have one string like 'raj, kumar, csd' and one more List which has
'raj'
'ASDF'
'EJSDA'
'ARHS'.

i want to compare both string and get matching string without foreach in C#.
can you help me guys?

Thanks in advance.
Posted
Comments
Richard MacCutchan 21-Apr-15 4:00am    
You cannot do that, since a list is a set of strings; you will need to use a loop.

1 solution

You need a loop of some kind - either explicit like foreach, for, or while; or implicit as with a Linq query:
C#
string findEm = "raj, kumar, csd";
List<string> matches = new List<string>() {"raj", "ASDF", "EJSDA", "ARHS"};
IEnumerable<string> found = findEm.Split(", ").Intersect(matches);
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900