How can I do something like IList <T> .Contains (OtherObjectType)?

I have the following classes:

Client

ClientCacheMedia (contains Client, Media and some other parameters, so this is the connection between the media and the client)

Mass media

where the client contains an IList. Now, what I would like to do is there is a way to check if this ilist contains a specific medium

like this: Client.ClientCacheMedia.Contains (MyMedia)

is there any way to let IList accept media as an object to match? (I can easily override the Equals property on ClientCacheMedia to check if the transferred media has passed the one that contains ClientCacheMedia.Media, this is just an Ilist that will not accept any other objects in the Contains method.

+5
source share
2 answers

In this case, you can use the extension method IEnumerable.Any. It could be something like this:

Client.ClientCacheMedia.Any(cm => cm.Media == myMedia);
+6
source

You can also do this:

boll temp = (Client.ClientCacheMedia).ToList().Contains(MyMedia);
0
source

All Articles