共用方式為


PortTypeCollection.Insert(Int32, PortType) 方法

定義

加入指定的 PortTypePortTypeCollection,於指定的以零起始的索引位置。

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

參數

index
Int32

以零起始的索引,portType 參數要在此處插入。

portType
PortType

要加入至集合的 PortType

例外狀況

index 參數小於零。

-或- index 參數大於 Count

範例

ServiceDescription^ myServiceDescription = ServiceDescription::Read( "MathService_CS.wsdl" );
PortTypeCollection^ myPortTypeCollection = myServiceDescription->PortTypes;
int noOfPortTypes = myServiceDescription->PortTypes->Count;
Console::WriteLine( "\nTotal number of PortTypes: {0}", noOfPortTypes );
PortType^ myNewPortType = myPortTypeCollection[ "MathServiceSoap" ];

// Get the index in the collection.
int index = myPortTypeCollection->IndexOf( myNewPortType );

Console::WriteLine( "Removing the PortType named {0}", myNewPortType->Name );

// Remove the PortType from the collection.
myPortTypeCollection->Remove( myNewPortType );
noOfPortTypes = myServiceDescription->PortTypes->Count;
Console::WriteLine( "\nTotal number of PortTypes: {0}", noOfPortTypes );

// Check whether the PortType exists in the collection.
bool bContains = myPortTypeCollection->Contains( myNewPortType );
Console::WriteLine( "Port Type'{0}' exists: {1}", myNewPortType->Name, bContains );
Console::WriteLine( "Adding the PortType" );

// Insert a new portType at the index location.
myPortTypeCollection->Insert( index, myNewPortType );
ServiceDescription myServiceDescription =
   ServiceDescription.Read("MathService_CS.wsdl");

PortTypeCollection myPortTypeCollection =
   myServiceDescription.PortTypes;
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.
myPortTypeCollection.Remove(myNewPortType);
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);
Dim myServiceDescription As ServiceDescription = _
   ServiceDescription.Read("MathService_VB.wsdl")

Dim myPortTypeCollection As PortTypeCollection = _
   myServiceDescription.PortTypes
Dim noOfPortTypes As Integer = myServiceDescription.PortTypes.Count
Console.WriteLine(ControlChars.Newline & _
   "Total number of PortTypes: " & noOfPortTypes.ToString())

Dim myNewPortType As PortType = myPortTypeCollection("MathServiceSoap")
' Get the index in the collection.
Dim index As Integer = myPortTypeCollection.IndexOf(myNewPortType)
Console.WriteLine("Removing the PortType named " & _
   myNewPortType.Name)

' Remove the PortType from the collection.
myPortTypeCollection.Remove(myNewPortType)
noOfPortTypes = myServiceDescription.PortTypes.Count
Console.WriteLine(ControlChars.Newline & _
   "Total number of PortTypes: " & noOfPortTypes.ToString())

' Check whether the PortType exists in the collection.
Dim bContains As Boolean = myPortTypeCollection.Contains(myNewPortType)
Console.WriteLine("Port Type'" & myNewPortType.Name & _
   "' exists: " & bContains.ToString())

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

備註

如果集合中的專案數目已經等於集合的容量,則會在插入新元素之前自動重新配置內部陣列,將容量加倍。

如果 參數的值 index 等於 Count ,則指定的 PortType 實例會加入 至 的 PortTypeCollection 結尾。

插入點後的專案會向下移動以容納新的元素。

適用於