Não é possível converter implicitamente o tipo da tarefa <>
Eu estou tentando dominar a sintaxe do método assíncrono no .NET 4.5. Eu pensei que tinha entendido os exemplos exatamente no entanto, não importa qual seja o tipo do método assíncrono (ieTask<T>
), Sempre recebo o mesmo tipo de erro na conversão de volta paraT
- o que eu entendi era praticamente automático. O código a seguir produz o erro:
Não é possível converter implicitamente o tipo 'System.Threading.Tasks.Task<System.Collections.Generic.List<int>>
' para 'System.Collections.Generic.List<int>
'
public List<int> TestGetMethod()
{
return GetIdList(); // compiler error on this line
}
async Task<List<int>> GetIdList()
{
using (HttpClient proxy = new HttpClient())
{
string response = await proxy.GetStringAsync("www.test.com");
List<int> idList = JsonConvert.DeserializeObject<List<int>>();
return idList;
}
}
Ele falhará se eu explicitamente lançar o resultado também. Este:
public List<int> TestGetMethod()
{
return (List<int>)GetIdList(); // compiler error on this line
}
um pouco previsivelmente resulta neste erro:
Não é possível converter o tipo 'System.Threading.Tasks.Task<System.Collections.Generic.List<int>>
' para 'System.Collections.Generic.List<int>
'
Qualquer ajuda muito apreciada.