Bagikan melalui


ContactManager.DeleteContact Metode

Definisi

PeerContact Menghapus atau PeerName dari ContactManager serekan lokal.

Overload

DeleteContact(PeerContact)

Menghapus yang ditentukan PeerContact dari ContactManager peer lokal.

DeleteContact(PeerName)

Menghapus yang PeerContact terkait dengan yang ditentukan PeerName dari ContactManager peer lokal.

DeleteContact(PeerContact)

Menghapus yang ditentukan PeerContact dari ContactManager peer lokal.

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)

Parameter

peerContact
PeerContact

PeerContact untuk menghapus dari ContactManager.

Pengecualian

peerContactadalah null.

Contoh

Contoh kode berikut menggambarkan cara menghapus PeerContact dari lokal ContactManager:

//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;
}

Keterangan

Memanggil metode ini membutuhkan PermissionState dari Unrestricted.

Lihat juga

Berlaku untuk

DeleteContact(PeerName)

Menghapus yang PeerContact terkait dengan yang ditentukan PeerName dari ContactManager peer lokal.

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)

Parameter

peerName
PeerName

yang PeerName terkait dengan PeerContact untuk menghapus dari ContactManager.

Atribut

Pengecualian

Yang PeerContact terkait dengan PeerName tidak dapat ditemukan di manajer kontak.

peerNameadalah null.

Objek ini sebelumnya telah Dispose() memanggilnya dan tidak dapat digunakan untuk operasi di masa mendatang.

Tidak dapat menyelesaikan DeleteContact operasi.

Contoh

Contoh kode berikut menggambarkan cara menghapus PeerContact dari lokal ContactManager:

//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;
}

Keterangan

Memanggil metode ini membutuhkan PermissionState dari Unrestricted.

Lihat juga

Berlaku untuk