Hello,
The returned object is of type IEnumerable<Contact>
, you can determine the type and declare it publicly. See IEnumerable<T> Interface (System.Collections.Generic) | Microsoft Learn
In addition, you can convert the type if you would like to. For more details, please refer to ObservableCollection<T> Class (System.Collections.ObjectModel) | Microsoft Learn
IEnumerable<Contact> contacts;
ObservableCollection<Contact> ContactsCollection;// I declare two fields
private async void OnCounterClicked(object sender, EventArgs e)
{
contacts = await Microsoft.Maui.ApplicationModel.Communication.Contacts.GetAllAsync();// this one is type of IEnumerable<Contact>
//var contacts = await Microsoft.Maui.ApplicationModel.Communication.Contacts.GetAllAsync();
// ContactsCollection = new ObservableCollection<Contact>(contacts); //
this one is type of ObservableCollection<Contact>
}
Best Regards,
Wenyan Zhang
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our documentationto enable e-mail notifications if you want to receive the related email notification for this thread.