简体   繁体   中英

Cannot convert IEnumerable type to IEnumerable

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 type IEnumerable<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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM