Pergunta

If

Ienumerable<Person> per = _serviceToGetPerson(); happens to only return one 'per' is it possible to assign it to a Person.

Person p = per.???

Foi útil?

Solução

You can use First/FirstOrDefault.

Person p = per.FirstOrDefault();

FirstOrDefault would return the first Object from the list or null if the List is empty.

You can also use Single / SingleOrDefault, if you are expecting only one item back from the list or only one or null (for SingleOrDefault)

Make sure that you have included using System.Linq; namespace

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top