MessageCollection.Item[] Property

Definition

Gets or sets the Message instance specified by the parameter passed in.

Overloads

Item[Int32]

Gets or sets the value of a Message at the specified zero-based index.

Item[String]

Gets a Message specified by its name.

Item[Int32]

Gets or sets the value of a Message at the specified zero-based index.

C#
public System.Web.Services.Description.Message this[int index] { get; set; }

Parameters

index
Int32

The zero-based index of the Message whose value is modified or returned.

Property Value

A Message.

Examples

The following example demonstrates the use of a zero-based index to iterate through the members of a MessageCollection.

C#
// Get Message Collection.
MessageCollection myMessageCollection = myServiceDescription.Messages;
Console.WriteLine("Total Messages in the document = " + myServiceDescription.Messages.Count);
Console.WriteLine("");
Console.WriteLine("Enumerating Messages...");
Console.WriteLine("");
// Print messages to console.
for(int i =0; i < myMessageCollection.Count; ++i)
{
   Console.WriteLine("Message Name : " + myMessageCollection[i].Name);
}

Applies to

.NET Framework 4.8.1 i druge verzije
Proizvod Verzije
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)

Item[String]

Gets a Message specified by its name.

C#
public System.Web.Services.Description.Message this[string name] { get; }

Parameters

name
String

The name of the Message returned.

Property Value

A Message.

Examples

The following example demonstrates the use of a string to retrieve a Message.

C#
// Get Message by Name = "AddSoapIn".
Message myMessage = myServiceDescription.Messages["AddSoapIn"];
Console.WriteLine("");
Console.WriteLine("Getting Message = 'AddSoapIn' {by Name}");
if (myMessageCollection.Contains(myMessage))
{
   Console.WriteLine("");
   // Get Message Name = "AddSoapIn" Index.
   Console.WriteLine("Message 'AddSoapIn' was found in Message Collection.");
   Console.WriteLine("Index of 'AddSoapIn' in Message Collection = " + myMessageCollection.IndexOf(myMessage));
   Console.WriteLine("Deleting Message from Message Collection...");
   myMessageCollection.Remove(myMessage);
   if(myMessageCollection.IndexOf(myMessage) == -1)
   {
      Console.WriteLine("Message 'AddSoapIn' was successfully removed from Message Collection.");
   }
}

Applies to

.NET Framework 4.8.1 i druge verzije
Proizvod Verzije
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 2.0 (package-provided)