This class represents a Perl hash.
|
Calling Count on the Hash will throw a NotImplementedException. Perl does not provide a direct way of determining the number of bindings in a hash, so no easy way is provided to the user. One can iterate through the Hash to determine the count, but beware of the hash's single-iterator semantics, described below.
Perl hashes have a funny problem: only one thing can iterate through a hash at a time. Multiple concurrent iterations (iterating through the Hash, its Keys collection, or its Values collection) will interfere with each other. An InvalidOperationException is thrown if this occurs while using an enumerator on the Hash.
The following example creates a new hash in the Perl interpreter's context. It then adds some mappings from strings to integers, and then displays the mapping. Creating hashes this way is only useful for passing the hash to sub and method calls, or as return values from extension objects.
| C# Example |
Interpreter perl = new Interpreter();
Hash h = new Hash(perl);
int ctr = 0;
foreach (string element in new string[] { "this", "is", "a", "test" }) {
h[element] = ctr;
}
foreach (Scalar key in h.Keys)
Console.WriteLine("The Hash Has: {0} => {1}", key, h[key]);
|
See Also: Inherited members from Value.
|
Hash(Interpreter) Creates a new, empty Hash. |
|
Item[Value] |
Value. Gets or sets the Value that corresponds to the given key. |
|
Item[object] |
object. Gets or sets the managed-style value that corresponds to the given key. |
|
Keys
[read-only]
|
ICollection. Returns the keys used in the hash. |
|
Values
[read-only]
|
ICollection. Returns the values contained in the hash. |
Creates a new, empty Hash.
Clears the hash.
Removes a binding from the hash.
Tests whether a key is used in the Hash.
Returns the keys used in the hash.
Returns the values contained in the hash.
Gets or sets the Value that corresponds to the given key.
Gets or sets the managed-style value that corresponds to the given key.