How can i do something like IList<T>.Contains(OtherObjectType)?
Asked Answered
N

2

5

I have the following classes:

Client

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

Media

where client contains an IList. Now what i would like to do, is have a way to check if this ilist contains a certain media

so : Client.ClientCacheMedia.Contains(MyMedia)

is there any way to let the IList accept media as an object to match ? ( i can easily override the Equals Property on ClientCacheMedia to check if the media passed is the one that the ClientCacheMedia.Media contains, it's just the Ilist that will not accept any other object on the Contains Method.

Norward answered 1/6, 2010 at 11:28 Comment(0)
S
7

You can use the extension method IEnumerable.Any in this case. It could be something like this:

Client.ClientCacheMedia.Any(cm => cm.Media == myMedia);
Shirleenshirlene answered 1/6, 2010 at 11:33 Comment(0)
K
0

You can do it in this way too:

boll temp = (Client.ClientCacheMedia).ToList().Contains(MyMedia);
Khalif answered 7/11, 2016 at 8:11 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.