par*_*fum 6 c# list count task
private async Task<List<T>> Ex_Event(string telNo)
{
SearchConditionData scd = new SearchConditionData { tel=telNo };
List<T> list = await RequestAsync<SearchConditionData, List<T>>(scd, Service.GetIncident);
historyList = ( ... ).Take(30).ToList();
return historyList;
}
Run Code Online (Sandbox Code Playgroud)
我做了一个返回 List<> 的方法。
但是我异步修改了它,然后我不能使用List.Count。
这是我的代码的一部分。
public delegate Task<List<IncidentListData>> HistoryEvent(string telNo);
public event HistoryEvent myHistoryEvent;
Run Code Online (Sandbox Code Playgroud)
返回类型是任务<>。我想检查任务中的计数列表。
if (myHistoryEvent(Tel).Count > 0)
Run Code Online (Sandbox Code Playgroud)
但它不起作用。而且我不能使用异步,因为我在接口中调用了 myHistoryEvent() public string this[string name](IDataErrorInfo)
如何检查任务中列表的数量??
您可以检查任务的结果。
myHistoryEvent(Tel).Result.Count > 0
Run Code Online (Sandbox Code Playgroud)
内部结果类型List Task>.Result。