2013-02-05 38 views

回答

0

我不知道ABAddressBook,但如果您使用Xamarin移動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

+0

要使用此示例實現我的目標,這將是一個嵌套的foreach,仍然表現會比較慢..如果我想重複的電話時,我需要循環的接觸,並通過他們獲得每一個,然後循環的電話獲取重複。 –

0

您可以在O做到這一點( N)時間。該答案使用一個循環來標識數組中的重複項:https://stackoverflow.com/a/12948182/1441667。試着將Stuarts的答案與這種方法結合起來。

+0

我不知道如何在我的程序中應用此功能。你有任何C#示例? –