MimePartCollection.Insert(Int32, MimePart) 方法

定义

将指定的 MimePart 添加到 MimePartCollection 中的指定索引处。

public:
 void Insert(int index, System::Web::Services::Description::MimePart ^ mimePart);
public void Insert (int index, System.Web.Services.Description.MimePart mimePart);
member this.Insert : int * System.Web.Services.Description.MimePart -> unit
Public Sub Insert (index As Integer, mimePart As MimePart)

参数

index
Int32

将在该处插入 mimePart 参数的从零开始的索引。

mimePart
MimePart

要添加到集合中的 MimePart

例外

index 参数小于零。

  • 或 - index 参数大于 Count

示例

以下示例演示了该方法的典型用法 Insert

MimeMultipartRelatedBinding^ myMimeMultipartRelatedBinding = nullptr;
IEnumerator^ myIEnumerator = myOutputBinding->Extensions->GetEnumerator();
while ( myIEnumerator->MoveNext() )
   myMimeMultipartRelatedBinding = (MimeMultipartRelatedBinding^)myIEnumerator->Current;

// Create an instance of 'MimePartCollection'.
MimePartCollection^ myMimePartCollection = gcnew MimePartCollection;
myMimePartCollection = myMimeMultipartRelatedBinding->Parts;
Console::WriteLine( "Total number of mimepart elements in the collection initially  is: {0}", myMimePartCollection->Count );

// Get the type of first 'Item' in collection.
Console::WriteLine( "The first object in collection is of type: {0}", myMimePartCollection[ 0 ] );
MimePart^ myMimePart1 = gcnew MimePart;

// Create an instance of 'MimeXmlBinding'.
MimeXmlBinding^ myMimeXmlBinding1 = gcnew MimeXmlBinding;
myMimeXmlBinding1->Part = "body";
myMimePart1->Extensions->Add( myMimeXmlBinding1 );

//  a mimepart at first position.
myMimePartCollection->Insert( 0, myMimePart1 );
Console::WriteLine( "Inserting a mimepart object..." );

// Check whether 'Insert' was successful or not.
if ( myMimePartCollection->Contains( myMimePart1 ) )
{
   // Display the index of inserted 'MimePart'.
   Console::WriteLine( "'MimePart' is successfully inserted at position: {0}", myMimePartCollection->IndexOf( myMimePart1 ) );
}
MimeMultipartRelatedBinding myMimeMultipartRelatedBinding = null;
IEnumerator myIEnumerator = myOutputBinding.Extensions.GetEnumerator();
while(myIEnumerator.MoveNext())
{
   myMimeMultipartRelatedBinding=(MimeMultipartRelatedBinding)myIEnumerator.Current;
}
// Create an instance of 'MimePartCollection'.
MimePartCollection myMimePartCollection = new MimePartCollection();
myMimePartCollection= myMimeMultipartRelatedBinding.Parts;
Console.WriteLine("Total number of mimepart elements in the collection initially"+
                     " is: " +myMimePartCollection.Count);
// Get the type of first 'Item' in collection.
Console.WriteLine("The first object in collection is of type: "
                  +myMimePartCollection[0].ToString());
MimePart myMimePart1=new MimePart();
// Create an instance of 'MimeXmlBinding'.
MimeXmlBinding myMimeXmlBinding1 = new MimeXmlBinding();
myMimeXmlBinding1.Part = "body";
myMimePart1.Extensions.Add(myMimeXmlBinding1);
//  a mimepart at first position.
myMimePartCollection.Insert(0,myMimePart1);
Console.WriteLine("Inserting a mimepart object...");
// Check whether 'Insert' was successful or not.
if(myMimePartCollection.Contains(myMimePart1))
{
   // Display the index of inserted 'MimePart'.
   Console.WriteLine("'MimePart' is successfully inserted at position: "
                        +myMimePartCollection.IndexOf(myMimePart1));
}
Dim myMimeMultipartRelatedBinding As MimeMultipartRelatedBinding = Nothing
Dim myIEnumerator As IEnumerator = myOutputBinding.Extensions.GetEnumerator()
While myIEnumerator.MoveNext()
   myMimeMultipartRelatedBinding = CType(myIEnumerator.Current, MimeMultipartRelatedBinding)
End While
' Create an instance of 'MimePartCollection'.
Dim myMimePartCollection As New MimePartCollection()
myMimePartCollection = myMimeMultipartRelatedBinding.Parts
Console.WriteLine("Total number of mimepart elements in the collection initially" + _
                                             " is: " + myMimePartCollection.Count.ToString())
' Get the type of first 'Item' in collection.
Console.WriteLine("The first object in collection is of type: " + _
                                                      myMimePartCollection.Item(0).ToString())
Dim myMimePart1 As New MimePart()
' Create an instance of 'MimeXmlBinding'.
Dim myMimeXmlBinding1 As New MimeXmlBinding()
myMimeXmlBinding1.Part = "body"
myMimePart1.Extensions.Add(myMimeXmlBinding1)
'  a mimepart at first position.
myMimePartCollection.Insert(0, myMimePart1)
Console.WriteLine("Inserting a mimepart object...")
' Check whether 'Insert' was successful or not.
If myMimePartCollection.Contains(myMimePart1) Then
   ' Display the index of inserted 'MimePart'.
   Console.WriteLine("'MimePart' is successfully inserted at position: " + _
                                      myMimePartCollection.IndexOf(myMimePart1).ToString())
End If

注解

如果集合中的项数已经等于集合的容量,则通过在插入新元素之前自动重新分配内部数组来增加容量。

index如果参数等于Count,则mimePart参数将添加到末尾MimePartCollection

插入点向下移动以容纳新元素的元素。

适用于