Reputation: 71
I don't understand why I can't assign a value returned from method of IEnumerable<Person>
to the same type. I am getting the message:
Cannot convert source type
IEnumerable<Person>
to target typeIEnumerable<Person>
.
Can anyone please suggest what's wrong with this code:
public IEnumerable<Person> GetPeople(IEnumerable<int> Ids)
{
return FindAll(m => Ids.Contains(m.Id)).ToList();
}
After calling this method trying to assign to the value of same type:
IEnumerable<Person> people = _myRepository.GetPeople(listOfIds);
I can assign to var, but I would like to declare this variable in class scope, so I am stuck.
Upvotes: 2
Views: 719
Reputation: 1446
In this case you have to use your Person with namespace:
public IEnumerable<[Namespace]> GetPeople(IEnumerable<int> Ids)
{
return FindAll(m => Ids.Contains(m.Id)).ToList();
}
IEnumerable<[Namespace].Person> people = _myRepository.GetPeople(listOfIds);
[Namespace] - namespace where Person
type is stored
Upvotes: 2