ContactManager.DeleteContact 메서드

정의

로컬 피어의 PeerContact에서 PeerName 또는 ContactManager을 제거합니다.

오버로드

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입니다.

예외

peerContact이(가) null인 경우

예제

다음 코드 예제에서는 삭제 하는 방법을 보여 줍니다.는 PeerContact 로컬에서 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;
}

설명

이 메서드를 호출 하려면를 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를 연락처 관리자에서 찾을 수 없습니다.

peerName이(가) null인 경우

이 개체에 대해 이전에 Dispose()가 호출되었으며 이후 작업에 사용할 수 없습니다.

DeleteContact 작업을 완료할 수 없는 경우.

예제

다음 코드 예제에서는 삭제 하는 방법을 보여 줍니다.는 PeerContact 로컬에서 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;
}

설명

이 메서드를 호출 하려면를 PermissionStateUnrestricted합니다.

추가 정보

적용 대상