0

我正在开发获取具有相同电话号码的重复联系人的应用程序。我的问题是常规的 foreach 与大量的联系很慢,我也知道使用谓词可以做到这一点。但我找不到任何带有单点触控的样品。

4

2 回答 2

0

我不知道 ABAddressBook,但如果您使用 Xamarin Mobile APi,那么您可以使用谓词,如下所示:

var abook = new AddressBook();
abook.RequestPermissions().ContinueWith (t =>
{
    if (!t.Result)
        return; // Permission denied

    var builder = new StringBuilder();

    // Full LINQ support
    foreach (Contact c in abook.Where (c => c.FirstName == "Eric" && c.Phones.Any()))
    {
        builder.AppendLine (c.DisplayName);
        foreach (Phone p in c.Phones)
            builder.AppendLine (String.Format ("{0}: {1}", p.Label, p.Number));

        builder.AppendLine();
    }

    contacts.Text = builder.ToString(); // Update UI

}, TaskScheduler.FromCurrentSynchronizationContext()); // Ensure we're on the UI Thread

来自http://betaapi.xamarin.com/?link=T%3aXamarin.Contacts.AddressBook

于 2013-02-05T18:33:40.700 回答
0

您可以在 O(N) 时间内完成。此答案使用一个循环来识别数组中的重复项: https ://stackoverflow.com/a/12948182/1441667 。尝试将 Stuarts 的答案与这种方法结合起来。

于 2013-02-06T12:37:09.967 回答