gpt4 book ai didi

c# - 无法将类型 'System.Collections.Generic.List<>' 隐式转换为 'System.Threading.Tasks.Task<>>

转载 作者:太空狗 更新时间:2023-10-30 00:10:00 27 4
gpt4 key购买 nike

我遇到了异常。

Cannot implicitly convert type 'System.Collections.Generic.List<IntegraPay.Domain.SObjects.Industry>' to 'System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<IntegraPay.Domain.SObjects.Industry>>'

下面是我的属性和方法。

  private List<WebFormFieldContent> WebFormFields { get; set; } = 
new List<WebFormFieldContent>();

Task<IEnumerable<WebFormFieldContent>> IRegistrationRepository.GetWebFormFields()
{
return WebFormFields;
}

最佳答案

此错误通常在您缺少 async 时发生在方法声明中。

当你输入 async在签名中,C# 编译器添加了“魔法”来完成从对象到 Task<T> 的转换。返回那个对象。

但是,在你的情况下async是不必要的,因为你返回一个任务,结果你已经有了:

return Task.FromResult<IEnumerable<WebFormFieldContent>>(
WebFormFields
);

关于c# - 无法将类型 'System.Collections.Generic.List<>' 隐式转换为 'System.Threading.Tasks.Task<>>,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38579354/

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