gpt4 book ai didi

c# - 使用 Task.ContinueWith 时并非所有代码路径都返回值

转载 作者:行者123 更新时间:2023-11-30 21:55:40 26 4
gpt4 key购买 nike

所以我有这个函数,我在所有 if-else 中都有返回,但仍然出现编译错误:

not all code paths return a value

public async Task<bool> DeletePost(string update_id, string authId)
{
if (Utility.NetworkStatus.HasInternetAccess)
{
await APIs.DeletePost.DeletePostAPI(update_id, authId).ContinueWith((t) =>
{
if (t.Status == TaskStatus.RanToCompletion)
{
if (t.Result != null)
{
return t.Result.status == 200;
}
else
{
return false;
//empty result, API failed
//not implemented
}
}
else
{
return false;
//task failed
//not implemented
}
});
}
else
{
return false;
//no network
//not implemented
}
}

谁能告诉我我做错了什么?

最佳答案

是的。您不返回 DeletePostAPI 的延续结果:

public async Task<bool> DeletePost(string update_id, string authId)
{
if (Utility.NetworkStatus.HasInternetAccess)
{
return await APIs.DeletePost.DeletePostAPI(update_id, authId).ContinueWith((t) =>
{
if (t.Status == TaskStatus.RanToCompletion)
{
if (t.Result != null)
{
return t.Result.status == 200;
}
else
{
return false;
//empty result, API failed
//not implemented
}
}
else
{
return false;
//task failed
//not implemented
}
});
}
else
{
return false;
//no network
//not implemented
}
}

关于c# - 使用 Task.ContinueWith 时并非所有代码路径都返回值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32096761/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com