共用方式為


MessageCollection.Remove(Message) 方法

定義

Message 中移除指定 MessageCollection 的第一個符合項目。

public:
 void Remove(System::Web::Services::Description::Message ^ message);
public void Remove (System.Web.Services.Description.Message message);
member this.Remove : System.Web.Services.Description.Message -> unit
Public Sub Remove (message As Message)

參數

message
Message

要從集合中移除的 Message

範例

下列範例示範 Remove 方法的用法。

// Get Message by Name = S"AddSoapIn".
Message^ myMessage = myServiceDescription->Messages[ "AddSoapIn" ];
Console::WriteLine( "" );
Console::WriteLine( "Getting Message = 'AddSoapIn' {by Name}" );
if ( myMessageCollection->Contains( myMessage ) )
{
   Console::WriteLine( "" );

   // Get Message Name = S"AddSoapIn" Index.
   Console::WriteLine( "Message 'AddSoapIn' was found in Message Collection." );
   Console::WriteLine( "Index of 'AddSoapIn' in Message Collection = {0}", myMessageCollection->IndexOf( myMessage ) );
   Console::WriteLine( "Deleting Message from Message Collection..." );
   myMessageCollection->Remove( myMessage );
   if ( myMessageCollection->IndexOf( myMessage ) == -1 )
         Console::WriteLine( "Message 'AddSoapIn' was successfully removed from Message Collection." );
}
// Get Message by Name = "AddSoapIn".
Message myMessage = myServiceDescription.Messages["AddSoapIn"];
Console.WriteLine("");
Console.WriteLine("Getting Message = 'AddSoapIn' {by Name}");
if (myMessageCollection.Contains(myMessage))
{
   Console.WriteLine("");
   // Get Message Name = "AddSoapIn" Index.
   Console.WriteLine("Message 'AddSoapIn' was found in Message Collection.");
   Console.WriteLine("Index of 'AddSoapIn' in Message Collection = " + myMessageCollection.IndexOf(myMessage));
   Console.WriteLine("Deleting Message from Message Collection...");
   myMessageCollection.Remove(myMessage);
   if(myMessageCollection.IndexOf(myMessage) == -1)
   {
      Console.WriteLine("Message 'AddSoapIn' was successfully removed from Message Collection.");
   }
}
' Get Message by Name = "AddSoapIn".
Dim myMessage As Message = myServiceDescription.Messages("AddSoapIn")
Console.WriteLine("")
Console.WriteLine("Getting Message = 'AddSoapIn' {by Name}")
If myMessageCollection.Contains(myMessage) Then
   Console.WriteLine("")
   ' Get Message Name = "AddSoapIn" Index.
   Console.WriteLine("Message 'AddSoapIn' was found in Message Collection.")
   Console.WriteLine("Index of 'AddSoapIn' in Message Collection = " + _
                     myMessageCollection.IndexOf(myMessage).ToString)
   Console.WriteLine("Deleting Message from Message Collection...")
   myMessageCollection.Remove(myMessage)
   If myMessageCollection.IndexOf(myMessage) = -1 Then
      Console.WriteLine("Message 'AddSoapIn' was successfully " + _
                        " removed from Message Collection.")
   End If
End If

備註

這個方法會執行線性搜尋;因此,平均執行時間與 成正比 Count

移除 Message 後的元素會向上移動,以佔用空空的地點。

適用於