-3

I have a list on were i select the ids and i want to see if one of those ids exists in another list of ids. How do i do that?

Im trying to do something like this:

 customerViewModel.Suppliers.Select(w => w.SupplierId).Contains(SessionCms.Suppliers.Select(a => a.SupplierId))

My sessioncms object is a list of suppliers and my customerviewmodel.suppliers is also a list of suppliers.

(here i just write some bullshit so that i meet the quality standards to post this question)

Daniel Gustafsson
  • 1,725
  • 7
  • 37
  • 78
  • possible duplicate of [Check if list contains any of another list](http://stackoverflow.com/questions/11092930/check-if-listt-contains-any-of-another-list) – MakePeaceGreatAgain Mar 02 '15 at 14:52

1 Answers1

0

There you go:

class Program {
    static void Main(string[] args) {
        bool contains = thisList.AnyOf(thatList, t => t.Property);
        Console.WriteLine(contains);
        Console.ReadKey(true);
    }
}

static class _ {
    public static bool AnyOf<T, P>(this IEnumerable<T> thisList, IEnumerable<T> thatList, Func<T, P> propertySelector) {
        foreach(P thisProperty in thisList.Select(propertySelector)) {
            foreach(P thatProperty in thatList.Select(propertySelector)) {
                if(thisProperty.Equals(thatProperty)) {
                    return true;
                }
            }
        }
        return false;
    }
}
Binkan Salaryman
  • 3,008
  • 1
  • 17
  • 29