check existense between two IEnumerable

Posted by sunglim on Stack Overflow See other posts from Stack Overflow or by sunglim
Published on 2010-06-10T11:16:06Z Indexed on 2010/06/10 11:22 UTC
Read the original article Hit count: 180

Filed under:
|
IEnumerable<String> existedThings = 
        from mdinfo in mdInfoTotal select mdinfo.ItemNo;

IEnumerable<String> thingsToSave = 
        from item in lbXReadSuccess.Items.Cast<ListItem>() select item.Value;

Here are two IEnumerable.

I want to check whether a value in existedThings exist in thingsToSave.

O.K. I can do that with 3 line code.

            bool hasItemNo;
            foreach(string itemNo in existedThings)
                hasItemNo= thingsToSave.Contains(itemNo);

But, It looks dirty.

I just want to know if there better solution.

© Stack Overflow or respective owner

Related posts about c#

Related posts about LINQ