![](/img/trans.png)
[英]The type arguments for method cannot be inferred from the usage. (c#, lambda)
[英]The type arguments for method cannot be inferred from the usage. C#
我正在嘗試制定節流方法,但遇到錯誤:
無法從用法中推斷出方法“Extensions.executeParallelWithReturn(IEnumerable, int, Func<T, List, Task>, List)”的類型 arguments。 嘗試明確指定類型 arguments。
public async Task ProcessThrottlingPaymentsByIds(List<List<Guid>> queue, int limit, List<Payment> ts)
{
await queue.executeParallelWithReturn(limit, GetGenericPaymentsByIds, ts);
}
我在“ProcessThrottlingPaymentsByIds”中遇到錯誤有什么想法我做錯了什么嗎?
public static async Task executeParallelWithReturn<T>(this IEnumerable<T> items, int limit, Func<T, List<T>, Task> actionMethod, List<T> ts)
{
var allTasks = new List<Task>(); //Store all Tasks
var activeTasks = new List<Task>();
foreach (var item in items)
{
if (activeTasks.Count >= limit)
{
var completedTask = await Task.WhenAny(activeTasks);
activeTasks.Remove(completedTask);
}
var task = actionMethod(item, ts);
allTasks.Add(task);
activeTasks.Add(task);
}
await Task.WhenAll(allTasks); // Wait for all task to complete
}
您在這里提供的信息相互矛盾。 讓我們看看我們有什么:
executeParallelWithReturn<T>(this IEnumerable<T> items, int limit, Func<T, List<T>, Task> actionMethod, List<T> ts)
這表示只有一個模板參數,因此所有內容都將具有一種類型。 您在List<List<Guid>>
類型的queue
上調用它,這意味着T
基於第一個參數是List<Guid>
類型。
但是你給它的ts
類型是List<Payments>
,這意味着T
應該突然變成Payments
類型。 不可能兩者兼而有之。
由於代碼沒有說明 guid 列表如何與Payments
object 相關,我無法說明如何修復它。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.