jsinq.Dictionary

Since its initial release, JSINQ has been expanded to also contain the two collection classes jsinq.List and jsinq.Dictionary. jsinq.Dictionary is a complete implementation of System.Collections.Generic.Dictionary. Unlike JavaScript's object type, jsinq.Dictionary supports arbitrary values as keys.

var dictionary = new jsinq.Dictionary();
dictionary.set("Hello", "World");
alert(dictionary.item("Hello")); // alerts "World"
var myKey = { foo: 123 };
dictionary.set(myKey, new Date());
alert(dictionary.containsKey(myKey)); // alerts "true"

You can also turn any jsinq.Enumerable into a dictionary by invoking its "toDictionary" method.

Methods

jsinq.Dictionary provides the following methods:

Method Static Description
item no Retrieves the value associated with the specified key
set no Sets the value associated with the specified key. An existing value associated with the key will be replaced.
count no Returns the number of key-value pairs in this dictionary
getComparer no Retrieves the comparer associated with this dictionary
add no Adds the specified key and value to the dictionary
tryAdd no Attempts to add the specified key and value to the dictionary. Returns a boolean value indicating whether the operation was successful.
keys no Returns an array containing the keys in this dictionary
values no Returns an array containing the values in this dictionary
clear no Empties the dictionary
containsKey no Returns a boolean value indicating whether the specified key is contained within the dictionary.
containsValue no Returns a boolean value indicating whether the specified value is contained within the dictionary
getEnumerator no Returns an enumerator that iterates over this dictionary
toArray no Returns an array containing the keys and values in this dictionary dictionary. Returns a boolean value indicating whether the operation was successful.
isReadOnly no Indicates whether this dictionary is read-only
toString no Returns a string representing the dictionary


Please check out the official .NET reference for additional information on how to use these methods: http://msdn.microsoft.com/en-us/library/xfhwa508.aspx
Also look at the comments in the source code and of course the examples.

Last edited Mar 27, 2010 at 2:16 PM by kaijaeger, version 2

Comments

No comments yet.