getting same type of inherited class items from base class list using linq
c#, linq
Solution
List<Tiger> tigers = animals.OfType<Tiger>().ToList();
Problem
``` class Animal { } class Tiger : Animal { } class Lion : Animal { } ``` Adding some animals(lions and tigers derived from parent `Animal` class) to the list of animals. ``` class Program { static void Main(string[] args) { List<Animal> animals = new List<Animal>(); animals.Add(new Tiger()); animals.Add(new Tiger()); animals.Add(new Tiger()); animals.Add(new Lion()); animals.Add(new Lion()); animals.Add(new Lion()); List<Tiger> tigers = new List<Tiger>(); foreach (var item in animals){ if(item is Tiger){ var _tiger = item as Tiger; tigers.Add(_tiger); } } } } ``` I would get the list of tigers using the above foreach loop, but is there any implementation to get the list if tigers using Linq, like `List<Tiger> tigers = animals.where(somePredicate)` ??