tags:

views:

67

answers:

3

Hi,

I have a collection of image paths, and a larger collection of Image objects (Which contain a path property). I have the code to check for any matching images, but if there are supposed to be four matching image paths (as that is how many are in the first collection), and there is less than this, how can I get the missing one without writing loops?

        List<string> ImagesToCheck = new List<string>()
        {
            "",
            "s",
            "ssdd"
        };

        IEnumerable<HtmlImage> Images = manager.ActiveBrowser.Find.AllControls<HtmlImage>();

        var v = from i in Images
                where ImagesToCheck.Any(x => x == i.Src)
                select i;

        if (v.Count() < 3)
        {

        }

So I need to get the items which are not in the collection titled v, but are in ImagesToCheck.

How could I do this with LINQ?

Thanks

+1  A: 

Try this..

var images = from s in ImagesToCheck where !i.Any(c => c.Path == s) select s;

Something along those lines..

Ian

Ian P
A: 

ImagesToCheck.Where(x => !v.Contains(x))

Jakob
A: 
var results = ImagesToCheck.Where(i => !v.Contains(i));

Kindness,

Dan

Daniel Elliott
`var results = ImagesToCheck.Where(i => !v.Contains( thisImage => thisImage.Path == i));` ?
ANeves