This documentation is archived and is not being maintained.
MessagePartCollection.IndexOf Method
.NET Framework 1.1
Searches for the specified MessagePart and returns the zero-based index of the first occurrence within the collection.
[Visual Basic] Public Function IndexOf( _ ByVal messagePart As MessagePart _ ) As Integer [C#] public int IndexOf( MessagePart messagePart ); [C++] public: int IndexOf( MessagePart* messagePart ); [JScript] public function IndexOf( messagePart : MessagePart ) : int;
Parameters
- messagePart
- The MessagePart for which to search in the collection.
Return Value
A 32-bit signed integer.
Example
[Visual Basic, C#, C++] The following example demonstrates a use of the IndexOf method to determine whether a specified MessagePart is a member of the collection.
[Visual Basic] Console.WriteLine("Checking if message is AddHttpPostOut...") Dim myMessage As Message = myServiceDescription.Messages("AddHttpPostOut") If myMessageCollection.Contains(myMessage) Then ' Get the message part collection. Dim myMessagePartCollection As MessagePartCollection = myMessage.Parts ' Get the part named Body. Dim myMessagePart As MessagePart = myMessage.Parts("Body") If myMessagePartCollection.Contains(myMessagePart) Then ' Get the index of the part named Body. Console.WriteLine("Index of Body in MessagePart collection = " & _ myMessagePartCollection.IndexOf(myMessagePart).ToString) Console.WriteLine("Deleting Body from MessagePart Collection...") myMessagePartCollection.Remove(myMessagePart) If myMessagePartCollection.IndexOf(myMessagePart) = -1 Then Console.WriteLine("MessagePart Body successfully deleted " & _ "from the message AddHttpPostOut.") End If End If End If [C#] Console.WriteLine("Checking if message is AddHttpPostOut..."); Message myMessage = myServiceDescription.Messages["AddHttpPostOut"]; if (myMessageCollection.Contains(myMessage)) { // Get the message part collection. MessagePartCollection myMessagePartCollection = myMessage.Parts; // Get the part named Body. MessagePart myMessagePart = myMessage.Parts["Body"]; if (myMessagePartCollection.Contains(myMessagePart)) { // Get the index of the part named Body. Console.WriteLine("Index of Body in MessagePart collection = " + myMessagePartCollection.IndexOf(myMessagePart)); Console.WriteLine("Deleting Body from MessagePart collection..."); myMessagePartCollection.Remove(myMessagePart); if(myMessagePartCollection.IndexOf(myMessagePart)== -1) { Console.WriteLine("MessagePart Body successfully deleted " + "from the message AddHttpPostOut."); } } } [C++] Console::WriteLine(S"Checking if message is AddHttpPostOut..."); Message* myMessage = myServiceDescription->Messages->Item[S"AddHttpPostOut"]; if (myMessageCollection->Contains(myMessage)) { // Get the mssage part collection. MessagePartCollection* myMessagePartCollection = myMessage->Parts; // Get the part named Body. MessagePart* myMessagePart = myMessage->Parts->Item[S"Body"]; if (myMessagePartCollection->Contains(myMessagePart)) { // Get the part named Body. Console::WriteLine(S"Index of Body in MessagePart collection = {0}", __box( myMessagePartCollection->IndexOf(myMessagePart))); Console::WriteLine(S"Deleting Body from MessagePart collection..."); myMessagePartCollection->Remove(myMessagePart); if (myMessagePartCollection->IndexOf(myMessagePart)== -1) Console::WriteLine(S"MessagePart Body successfully deleted "\ S"from the message AddHttpPostOut."); } }
[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button
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
MessagePartCollection Class | MessagePartCollection Members | System.Web.Services.Description Namespace
Show: