I am trying to get a list of objects from a list by comparing an enum that is passed into the method.
public List<IAnimal> GetListOfAnimalsByType(IAnimal.AnimalType animalType)
{
List<IAnimal> animalTypeList = animalList.SelectMany(ani => ani.Type == animaleType);
if(animalTypeList != null)
{
return animalTypeList;
}
else
{
return null;
}
}

It looks like you really just want Where instead of SelectMany:
public List<IAnimal> GetListOfAnimalsByType(IAnimal.AnimalType animalType)
{
return animalList.Where(ani => ani.Type == animaleType).ToList();
}
SelectMany is used to extract one sequence from each element within an original sequence, and usually "flatten" the resulting sequences together... whereas Where is used for filtering.
Additionally:
ToList() call is necessary because LINQ returns IEnumerable<T> or IQueryable<T>, not List<T>if statement is unnecessary as sequence-producing LINQ operators (e.g. Where, Select etc never return null; they'll return an empty sequence if necessaryanimalTypeList in both cases... "if the value is null, return null, otherwise return the value"... so you could still just return the result of the call
See more on this question at Stackoverflow