Compartir a través de


ListIterator.Insert(Object) Method

Definition

Inserts a new value at the position in the list that the iterator currently points to.

public:
 virtual System::Object ^ Insert(System::Object ^ value);
public virtual object Insert (object value);
abstract member Insert : obj -> obj
override this.Insert : obj -> obj
Public Overridable Function Insert (value As Object) As Object

Parameters

value
Object

The value of the item to insert into the list.

Returns

The value that was inserted into the list.

Remarks

The value parameter must be the same type as the list.

The following example creates a list that has ten items and then uses the ListIterator.insert method to insert a new value as the third item in the list.

{ 
    List il = new List(Types::Integer); 
    ListIterator it; 
    int i; 
    int j = 25; 
    // Insert values 1 to 10 into the list 
    for (i = 1; i <= 10; i++) 
    { 
        il.addEnd(i); 
    } 
    // Go to the 3rd element in the list 
    it = new ListIterator(il); 
    it.begin(); 
    it.next(); 
    it.next(); 
    // Insert a new value (25) 
    it.insert(j); 
  it.begin(); 
    // Print all values in the list. 
    // 25 is the third value in the list 
    while (it.more()) 
    { 
        print it.value(); 
        it.next();  
    } 
    pause; 
}

Applies to