gpt4 book ai didi

c# - Task> 不包含 where 的定义

转载 作者:行者123 更新时间:2023-11-30 20:31:12 36 4
gpt4 key购买 nike

我正在尝试按保存在其中的日期过滤可观察集合。用户将使用日历 View 选择日期。

public async Task RefreshItems(bool showActivityIndicator, bool syncItems)
{
using (var scope = new ActivityIndicatorScope(syncIndicator, showActivityIndicator))
{

var items = manager.GetAppointmentItemsAsync();


CalendarVM vm = new CalendarVM();
calendar.SetBinding(Calendar.DateCommandProperty, nameof(vm.DateChosen));
calendar.SetBinding(Calendar.SelectedDateProperty, nameof(vm.DateSelected));
calendar.BindingContext = vm;

var filtered = items.Where(appointmentItem => appointmentItem.Date == SelectedDate);
}
}

以下是 AppointmentPage 类中的代码,其中包含用户选择的日期和数据。

  public async Task<ObservableCollection<AppointmentItem>> GetAppointmentItemsAsync(bool syncItems = false)
{


try
{

IEnumerable<AppointmentItem> items = await appointmentTable
.ToEnumerableAsync();

return new ObservableCollection<AppointmentItem>(items);

}
catch (MobileServiceInvalidOperationException msioe)
{
Debug.WriteLine(@"Invalid sync operation: {0}", msioe.Message);
}
catch (Exception e)
{
Debug.WriteLine(@"Sync error: {0}", e.Message);
}
return null;

}

这是 dataManger 类中用于从数据库检索数据的代码。

目前我收到此错误:

Error CS1061 'Task>' does not contain a definition for 'Where' and no extension method 'Where' accepting a first argument of type 'Task>' could be found (are you missing a using directive or an assembly reference?

最佳答案

您的以下代码行:

var items = manager.GetAppointmentItemsAsync();

返回 Task显然不包含 Where这就是您收到错误的原因。

请将此行更改为:

var items = await manager.GetAppointmentItemsAsync();

然后你会得到一个 ObservableCollection<AppointmentItem> 类型的集合其中应该有 Where成员(member)。

关于c# - Task<ObservableCollection<AppointmentItem>> 不包含 where 的定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43559299/

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