Language

ContactManager.DeleteContact メソッド

定義

ローカル ピアのPeerContactからPeerNameまたはContactManagerを削除します。

オーバーロード

名前 説明
DeleteContact(PeerContact)

ローカル ピアのPeerContactから、指定したContactManagerを削除します。

DeleteContact(PeerName)

ローカル ピアのPeerContactから、指定したPeerNameに関連付けられているContactManagerを削除します。

DeleteContact(PeerContact)

ローカル ピアのPeerContactから、指定したContactManagerを削除します。

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

注釈

このメソッドを呼び出す場合は、PermissionStateのUnrestrictedが必要です。

こちらもご覧ください

適用対象

DeleteContact(PeerName)

ローカル ピアのPeerContactから、指定したPeerNameに関連付けられているContactManagerを削除します。

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

PeerNameから削除するPeerContactに関連付けられているContactManager。

属性

例外

PeerContactに関連付けられているPeerNameが連絡先マネージャーで見つかりませんでした。

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

注釈

このメソッドを呼び出す場合は、PermissionStateのUnrestrictedが必要です。

こちらもご覧ください

適用対象