共用方式為


MessagePartCollection.CopyTo(MessagePart[], Int32) 方法

定義

複製整個 MessagePartCollectionMessagePart 型別的相容一維陣列,從目標陣列的指定以零起始的索引位置開始。

public:
 void CopyTo(cli::array <System::Web::Services::Description::MessagePart ^> ^ array, int index);
public void CopyTo (System.Web.Services.Description.MessagePart[] array, int index);
member this.CopyTo : System.Web.Services.Description.MessagePart[] * int -> unit
Public Sub CopyTo (array As MessagePart(), index As Integer)

參數

array
MessagePart[]

MessagePart 型別的陣列,做為複製動作目的端。

index
Int32

以零起始的索引,要於此處開始放置複製的集合。

範例

下列範例示範 如何使用 CopyTo 方法。

Message^ myLocalMessage = myServiceDescription->Messages[ "AddHttpPostOut" ];
if ( myMessageCollection->Contains( myLocalMessage ) )
{
   Console::WriteLine( "Message      : {0}", myLocalMessage->Name );

   // Get the message part collection.
   MessagePartCollection^ myMessagePartCollection = myLocalMessage->Parts;
   array<MessagePart^>^myMessagePart = gcnew array<MessagePart^>(myMessagePartCollection->Count);
   
   // Copy the MessagePartCollection to an array.
   myMessagePartCollection->CopyTo( myMessagePart, 0 );
   for ( int k = 0; k < myMessagePart->Length; k++ )
      Console::WriteLine( "\t       Part Name : {0}", myMessagePartCollection[ k ]->Name );
   Console::WriteLine( "" );
}
Message myLocalMessage = myServiceDescription.Messages["AddHttpPostOut"];
if (myMessageCollection.Contains(myLocalMessage))
{
   Console.WriteLine("Message      : " + myLocalMessage.Name);

   // Get the message part collection.
   MessagePartCollection myMessagePartCollection = myLocalMessage.Parts;
   MessagePart[] myMessagePart  =
      new MessagePart[myMessagePartCollection.Count];

   // Copy the MessagePartCollection to an array.
   myMessagePartCollection.CopyTo(myMessagePart,0);
   for(int k = 0; k < myMessagePart.Length; k++)
   {
      Console.WriteLine("\t       Part Name : " +
         myMessagePartCollection[k].Name);
   }
   Console.WriteLine("");
}
Dim myLocalMessage As Message = _
   myServiceDescription.Messages("AddHttpPostOut")
If myMessageCollection.Contains(myLocalMessage) Then
   Console.WriteLine("Message      : " & myLocalMessage.Name)

   ' Get the message part collection.
   Dim myMessagePartCollection As MessagePartCollection = _
      myLocalMessage.Parts
   Dim myMessagePart(myMessagePartCollection.Count) As MessagePart

   ' Copy the MessagePartCollection to an array.
   myMessagePartCollection.CopyTo(myMessagePart, 0)
   Dim k As Integer
   For k = 0 To myMessagePart.Length - 2
      Console.WriteLine(ControlChars.Tab & "       Part Name : " & _
         myMessagePartCollection(k).Name)
   Next k
   Console.WriteLine("")
End If

適用於