markzzz
markzzz

Reputation: 47945

Cast an object to an array of string?

I have this code:

Strutture = from Ricettivito s in Strutture
            where s.ServiziAttivi.Cast<string>().Intersect(IDSServizi).Count() == IDSServizi.Count()
            select s;

I need to:

  1. Cast ServiziAttivi (which is a list of MyService) into a list of string (which must contains MyService.UniqueID)
  2. Than, check if this list contains each elements of IDSServizi (which is a list of string).

But seems I cannot doint that conversion?

Upvotes: 0

Views: 100

Answers (2)

I4V
I4V

Reputation: 35353

First cast to .Cast<Ricettivita.MyService>() then select a string property.

    where s.ServiziAttivi
             .Cast<Ricettivita.MyService>()
             .Select(x=>x.UniqueID).Intersect(IDSServizi).Count()

Upvotes: 4

MarcinJuraszek
MarcinJuraszek

Reputation: 125630

I think you should use Select instead of Cast:

Strutture = from Ricettivito s in Strutture
            where s.ServiziAttivi.Select(x => (string)x.UniqueID).Intersect(IDSServizi).Count() == IDSServizi.Count()
            select s;

Upvotes: 1

Related Questions