This documentation is archived and is not being maintained.

MimePartCollection.IndexOf Method

Searches for the specified MimePart and returns the zero-based index of the first occurrence within the collection.

[Visual Basic]
Public Function IndexOf( _
   ByVal mimePart As MimePart _
) As Integer
[C#]
public int IndexOf(
 MimePart mimePart
);
[C++]
public: int IndexOf(
 MimePart* mimePart
);
[JScript]
public function IndexOf(
   mimePart : MimePart
) : int;

Parameters

mimePart
The MimePart for which to search the MimePartCollection.

Return Value

A 32-bit signed integer.

Example

[Visual Basic, C#, C++] The following example demonstrates a typical use of the IndexOf method.

[Visual Basic] 
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 succesfully inserted at position: " + _
                                      myMimePartCollection.IndexOf(myMimePart1).ToString())
End If

[C#] 
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 succesfully inserted at position: "
                        +myMimePartCollection.IndexOf(myMimePart1));         
}

[C++] 
MimeMultipartRelatedBinding* myMimeMultipartRelatedBinding = 0;
IEnumerator* myIEnumerator = myOutputBinding->Extensions->GetEnumerator();
while(myIEnumerator->MoveNext())
   myMimeMultipartRelatedBinding = 
   dynamic_cast<MimeMultipartRelatedBinding*>(myIEnumerator->Current);
// Create an instance of 'MimePartCollection'.
MimePartCollection* myMimePartCollection = new MimePartCollection();
myMimePartCollection= myMimeMultipartRelatedBinding->Parts;
Console::WriteLine(S"Total number of mimepart elements in the collection initially  is: {0}", 
   __box(myMimePartCollection->Count));
// Get the type of first 'Item' in collection.
Console::WriteLine(S"The first object in collection is of type: {0}", 
   myMimePartCollection->Item[0]);
MimePart* myMimePart1 = new MimePart();
// Create an instance of 'MimeXmlBinding'.
MimeXmlBinding* myMimeXmlBinding1 = new MimeXmlBinding();
myMimeXmlBinding1->Part = S"body";
myMimePart1->Extensions->Add(myMimeXmlBinding1);
//  a mimepart at first position.
myMimePartCollection->Insert(0, myMimePart1);
Console::WriteLine(S"Inserting a mimepart object...");
// Check whether 'Insert' was successful or not.
if (myMimePartCollection->Contains(myMimePart1))
{
   // Display the index of inserted 'MimePart'.
   Console::WriteLine(S"'MimePart' is succesfully inserted at position: {0}", 
      __box(myMimePartCollection->IndexOf(myMimePart1)));
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family

See Also

MimePartCollection Class | MimePartCollection Members | System.Web.Services.Description Namespace

Show: