PortTypeCollection.Insert Method (Int32, PortType)


Adds the specified PortType to the PortTypeCollection at the specified zero-based index.

Namespace:   System.Web.Services.Description
Assembly:  System.Web.Services (in System.Web.Services.dll)

public void Insert(
	int index,
	PortType portType


Type: System.Int32

The zero-based index at which to insert the portType parameter.

Type: System.Web.Services.Description.PortType

The PortType to add to the collection.

Exception Condition

The index parameter is less than zero.

- or -

The index parameter is greater than Count.

If the number of items in the collection already equals the collection's capacity, the capacity is doubled by automatically reallocating the internal array before the new element is inserted.

If the value of the index parameter is equal to Count, the specified PortType instance is added to the end of the PortTypeCollection.

The elements after the insertion point move down to accommodate the new element.

ServiceDescription myServiceDescription = 

PortTypeCollection myPortTypeCollection = 
int noOfPortTypes = myServiceDescription.PortTypes.Count;
Console.WriteLine("\nTotal number of PortTypes: " + noOfPortTypes);

PortType myNewPortType = myPortTypeCollection["MathServiceSoap"];

// Get the index in the collection.
int index = myPortTypeCollection.IndexOf(myNewPortType);
Console.WriteLine("Removing the PortType named " 
   + myNewPortType.Name);

// Remove the PortType from the collection.
noOfPortTypes = myServiceDescription.PortTypes.Count;
Console.WriteLine("\nTotal number of PortTypes: " 
   + noOfPortTypes);

// Check whether the PortType exists in the collection.
bool bContains = myPortTypeCollection.Contains(myNewPortType);
Console.WriteLine("Port Type'" + myNewPortType.Name + "' exists: " 
   + bContains );

Console.WriteLine("Adding the PortType");
// Insert a new portType at the index location.
myPortTypeCollection.Insert(index, myNewPortType);

.NET Framework
Available since 1.1
Return to top