Jaa


MapIterator.key Method

Definition

Returns the key from the (key, value) pair that is referred to by the iterator.

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

Returns

The key value of the map entry that is denoted by the iterator.

Remarks

Use the SetIterator.more method to test whether an element exists before you try to retrieve the key value of the map element.

The following example iterates through a map and returns a description of all the elements in the map.

static str writeMap (Map m) 
{ 
    MapIterator it = new MapIterator(m); 
    str result; 
    while (it.more()) 
    { 
        result += it.key() + '\n' + it.value() + '\n'; 
        it.next(); 
    } 
    return result; 
}

Applies to