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

定义

将整个 MessagePartCollection 复制到兼容的、MessagePart 类型的一维数组(从目标数组的指定的从零开始的索引处开始复制)。

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

适用于