-9

I try to detect that AirCoNam1 field exist into airlines list or no. I wrote this linq query but get error.

aFlightList is a collection that contain AirCoNam1 field.

How to fix this?

  aFlightList=aFlightList.Any(  airlines.Contains(x=>x.AirCoNam1)).ToArray();
hmahdavi
  • 2,250
  • 3
  • 38
  • 90

3 Answers3

0

You can use the Intersect Linq method

var doesContain = aFlightList.Intersect(airlines.Select(a => a.AirCoNam1)).Any();
David Pilkington
  • 13,528
  • 3
  • 41
  • 73
  • @programmer138200 in what way? – David Pilkington May 18 '16 at 11:11
  • 1
    @programmer138200 It's impossible to help anyone who doesn't let people help him, "it doesn't work" isn't helpful, what doesn't work, what error are you getting, what output are you getting and what output do you expect. Just saying it doesn't work is no help at all – Ronan Thibaudau May 18 '16 at 11:22
0

The right way is this :

  aFlightList=aFlightList.Where(x=>airlines.Contains(x.AirCoNam1)).ToArray();
hmahdavi
  • 2,250
  • 3
  • 38
  • 90
0

Any() returns boolean. You can't call ToList() on a boolean value. It isn't clear from the question, but looks like you want to use Any() in a where clause, something like the following :

aFlightList = aFlightList.Where(f => airlines.Any(a => a == f.AirCoNam1))
                         .ToArray();
har07
  • 88,338
  • 12
  • 84
  • 137