共用方式為


ContactManager.DeleteContact 方法

定義

從本機對等電腦的 PeerContact 移除 PeerNameContactManager

多載

DeleteContact(PeerContact)

從本機對等項目的 ContactManager 中移除指定的 PeerContact

DeleteContact(PeerName)

從本機對等項目的 ContactManager 中移除與指定 PeerName 相關聯的 PeerContact

DeleteContact(PeerContact)

從本機對等項目的 ContactManager 中移除指定的 PeerContact

public:
 void DeleteContact(System::Net::PeerToPeer::Collaboration::PeerContact ^ peerContact);
public void DeleteContact (System.Net.PeerToPeer.Collaboration.PeerContact peerContact);
member this.DeleteContact : System.Net.PeerToPeer.Collaboration.PeerContact -> unit
Public Sub DeleteContact (peerContact As PeerContact)

參數

peerContact
PeerContact

要從 PeerContact 移除的 ContactManager

例外狀況

peerContactnull

範例

下列程式代碼範例說明如何從本機 ContactManager刪除 PeerContact

//Enumerating the contacts and letting the user choose which one to delete.
public static void DeleteContact()
{
    PeerContactCollection pcc = null;
    string contactToDelete = "";

    try
    {
        pcc = EnumContacts();
        if (pcc == null ||
            pcc.Count == 0)
        {
            Console.WriteLine("Contact list is empty -- no such contact exists.");
            return;
        }
        Console.Write("Please enter the nickname of the contact you wish to delete: ");
        contactToDelete = Console.ReadLine();

        foreach (PeerContact pc in pcc)
        {
            if (pc.Nickname.Equals(contactToDelete))
            {
                PeerCollaboration.ContactManager.DeleteContact(pc);
                Console.WriteLine("Contact {0} successfully deleted!", contactToDelete);
                return;
            }
        }
        Console.WriteLine("Contact {0} could not be found in the contact collection.", contactToDelete);
    }
    catch (ArgumentNullException argNullEx)
    {
        Console.WriteLine("The supplied contact is null: {0}", argNullEx.Message);
    }
    catch (ArgumentException argEx)
    {
        Console.WriteLine("The supplied contact \"{0}\" could not be found in the Contact Manager: {1}",
            contactToDelete, argEx.Message);
    }
    catch (PeerToPeerException p2pEx)
    {
        Console.WriteLine("The Peer Collaboration Infrastructure could not delete \"{0}\": {1}",
            contactToDelete, p2pEx.Message);
    }
    catch (Exception ex)
    {
        Console.WriteLine("Unexpected exception when trying to delete a contact : {0}", ex);
    }
    return;
}

備註

呼叫這個方法需要 PermissionStateUnrestricted

另請參閱

適用於

DeleteContact(PeerName)

從本機對等項目的 ContactManager 中移除與指定 PeerName 相關聯的 PeerContact

public:
 void DeleteContact(System::Net::PeerToPeer::PeerName ^ peerName);
[System.Security.SecurityCritical]
public void DeleteContact (System.Net.PeerToPeer.PeerName peerName);
[<System.Security.SecurityCritical>]
member this.DeleteContact : System.Net.PeerToPeer.PeerName -> unit
Public Sub DeleteContact (peerName As PeerName)

參數

peerName
PeerName

與要從 ContactManager 移除之 PeerContact 相關聯的 PeerName

屬性

例外狀況

在連絡人管理員中找不到與 PeerName 相關聯的 PeerContact

peerNamenull

此物件先前已在其上呼叫 Dispose(),而且無法用於未來的作業。

無法完成 DeleteContact 作業。

範例

下列程式代碼範例說明如何從本機 ContactManager刪除 PeerContact

//Enumerating the contacts and letting the user choose which one to delete.
public static void DeleteContact()
{
    PeerContactCollection pcc = null;
    string contactToDelete = "";

    try
    {
        pcc = EnumContacts();
        if (pcc == null ||
            pcc.Count == 0)
        {
            Console.WriteLine("Contact list is empty -- no such contact exists.");
            return;
        }
        Console.Write("Please enter the nickname of the contact you wish to delete: ");
        contactToDelete = Console.ReadLine();

        foreach (PeerContact pc in pcc)
        {
            if (pc.Nickname.Equals(contactToDelete))
            {
                PeerCollaboration.ContactManager.DeleteContact(pc);
                Console.WriteLine("Contact {0} successfully deleted!", contactToDelete);
                return;
            }
        }
        Console.WriteLine("Contact {0} could not be found in the contact collection.", contactToDelete);
    }
    catch (ArgumentNullException argNullEx)
    {
        Console.WriteLine("The supplied contact is null: {0}", argNullEx.Message);
    }
    catch (ArgumentException argEx)
    {
        Console.WriteLine("The supplied contact \"{0}\" could not be found in the Contact Manager: {1}",
            contactToDelete, argEx.Message);
    }
    catch (PeerToPeerException p2pEx)
    {
        Console.WriteLine("The Peer Collaboration Infrastructure could not delete \"{0}\": {1}",
            contactToDelete, p2pEx.Message);
    }
    catch (Exception ex)
    {
        Console.WriteLine("Unexpected exception when trying to delete a contact : {0}", ex);
    }
    return;
}

備註

呼叫這個方法需要 PermissionStateUnrestricted

另請參閱

適用於