Toggle menu
876
3.8K
30.2K
279.1K
Catglobe Wiki
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

Dictionary class: Difference between revisions

From Catglobe Wiki
Tungocman (talk | contribs)
No edit summary
Dennis (talk | contribs)
No edit summary
Line 1: Line 1:
=== '''Dictionary : The dictionary object'''  ===
{{CGscriptClass_Template
|Name=<nowiki>Dictionary</nowiki>
|Description=<nowiki>The dictionary object</nowiki>
|Constructors=
{{CGscriptConstructors_Template|Description=<nowiki>Create a new dictionary with non-argument.</nowiki>}}
{{CGscriptConstructors_Template|Parameters={{CGscriptParameters_Template|Type=params AnyType|Name=params AnyType|Description=}}
|Description=<nowiki>Create new dictionary with the specified key-value pairs.</nowiki>}}
{{CGscriptConstructors_Template|Parameters=
{{CGscriptParameters_Template|Type=array|Name=<nowiki>keys</nowiki>|Description=<nowiki>keys arrayConstant</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=array|Name=<nowiki>values</nowiki>|Description=<nowiki>values arrayConstant</nowiki>}}
|Description=<nowiki>Create new dictionary with the specified keys and values.</nowiki>}}
|Methods=
{{CGscriptMethods_Template|ReturnType=bool|Name=<nowiki>Add</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=string|Name=<nowiki>key</nowiki>|Description=<nowiki>Add with specific key</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=AnyType|Name=<nowiki>value</nowiki>|Description=<nowiki>Add with specific value</nowiki>}}
|Description=<nowiki>Adds the specified key and value to the dictionary.</nowiki>}}
{{CGscriptMethods_Template|ReturnType=bool|Name=<nowiki>Add</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=number|Name=<nowiki>key</nowiki>|Description=<nowiki>Add with specific key</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=AnyType|Name=<nowiki>value</nowiki>|Description=<nowiki>Add with specific value</nowiki>}}
|Description=<nowiki>Adds the specified key and value to the dictionary.</nowiki>}}
{{CGscriptMethods_Template|ReturnType=Empty|Name=<nowiki>Clear</nowiki>|Description=<nowiki>Remove all keys and values from the dictionary.</nowiki>}}
{{CGscriptMethods_Template|ReturnType=bool|Name=<nowiki>ContainsKey</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=string|Name=<nowiki>key</nowiki>|Description=<nowiki>Check with specific key</nowiki>}}
|Description=<nowiki>Determines whether the dictionary contains the specified key.</nowiki>}}
{{CGscriptMethods_Template|ReturnType=bool|Name=<nowiki>ContainsKey</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=number|Name=<nowiki>key</nowiki>|Description=<nowiki>Check with specific key</nowiki>}}
|Description=<nowiki>Determines whether the dictionary contains the specified key.</nowiki>}}
{{CGscriptMethods_Template|ReturnType=bool|Name=<nowiki>ContainsValue</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=AnyType|Name=<nowiki>value</nowiki>|Description=<nowiki>Add with specific value</nowiki>}}
|Description=<nowiki>Determines whether the dictionary contains the specified value.</nowiki>}}
{{CGscriptMethods_Template|ReturnType=AnyType|Name=<nowiki>this[] { get; }</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=string|Name=<nowiki>key</nowiki>|Description=<nowiki>The key used to lookup the value.</nowiki>}}
|Description=<nowiki>Get an item based on a key.</nowiki>}}
{{CGscriptMethods_Template|ReturnType=AnyType|Name=<nowiki>this[] { get; }</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=number|Name=<nowiki>key</nowiki>|Description=<nowiki>The key used to lookup the value.</nowiki>}}
|Description=<nowiki>Get an item based on a key.</nowiki>}}
{{CGscriptMethods_Template|ReturnType=AnyType|Name=<nowiki>Remove</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=string|Name=<nowiki>key</nowiki>|Description=<nowiki>Check with specific key</nowiki>}}
|Description=<nowiki>Remove the value with the specified key from the dictionary.</nowiki>}}
{{CGscriptMethods_Template|ReturnType=AnyType|Name=<nowiki>Remove</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=number|Name=<nowiki>key</nowiki>|Description=<nowiki>Remove with specific key</nowiki>}}
|Description=<nowiki>Remove the value with the specified key from the dictionary.</nowiki>}}
{{CGscriptMethods_Template|ReturnType=Empty|Name=<nowiki>this[] { set; }</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=string|Name=<nowiki>key</nowiki>|Description=<nowiki>The key used to lookup the value.</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=AnyType|Name=<nowiki>value</nowiki>|Description=<nowiki>The value to set.</nowiki>}}
|Description=<nowiki>Set an item based on a key and a value.</nowiki>}}
{{CGscriptMethods_Template|ReturnType=Empty|Name=<nowiki>this[] { set; }</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=number|Name=<nowiki>key</nowiki>|Description=<nowiki>The key used to lookup the value.</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=AnyType|Name=<nowiki>value</nowiki>|Description=<nowiki>The value to set.</nowiki>}}
|Description=<nowiki>Set an item based on a key and a value.</nowiki>}}
{{CGscriptMethods_Template|ReturnType=string|Name=<nowiki>ToString</nowiki>|Description=<nowiki>The string representation of the object.</nowiki>}}
{{CGscriptMethods_Template|ReturnType=AnyType|Name=<nowiki>TryGetValue</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=string|Name=<nowiki>key</nowiki>|Description=<nowiki>Remove with specific key</nowiki>}}
|Description=<nowiki>Gets the value associated with the specified key.</nowiki>}}
{{CGscriptMethods_Template|ReturnType=AnyType|Name=<nowiki>TryGetValue</nowiki>|Parameters=
{{CGscriptParameters_Template|Type=number|Name=<nowiki>key</nowiki>|Description=<nowiki>Remove with specific key</nowiki>}}
|Description=<nowiki>Gets the value associated with the specified key.</nowiki>}}
|Properties=
{{CGscriptProperties_Template|ReturnType=number|Name=<nowiki>Count</nowiki>|HasGetter=1|Description=<nowiki>Gets the number of key/value pairs contained in the dictionary.</nowiki>}}
{{CGscriptProperties_Template|ReturnType=array|Name=<nowiki>Keys</nowiki>|HasGetter=1|Description=<nowiki>Gets a list of keys.</nowiki>}}
{{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>ObjectTypeName</nowiki>|HasGetter=1|Description=<nowiki>The name of the type of object.</nowiki>}}
{{CGscriptProperties_Template|ReturnType=array|Name=<nowiki>SortedKeys</nowiki>|HasGetter=1|Description=<nowiki>Gets a list of keys sorted by current collation.</nowiki>}}
{{CGscriptProperties_Template|ReturnType=TypeInformation|Name=<nowiki>TypeInformation</nowiki>|HasGetter=1|Description=<nowiki>Get information about this class.</nowiki>}}
{{CGscriptProperties_Template|ReturnType=array|Name=<nowiki>Values</nowiki>|HasGetter=1|Description=<nowiki>Gets a list of values.</nowiki>}}
}}


&nbsp;
==== <span style="color:#a52a2a;">'''Constructors'''</span>  ====
*<span style="color:#000000;">'''()''' - Create a new dictionary with non-argument.</span>
*<span style="color:#000000;">'''(Params&nbsp; AnyType)''' - Create new dictionary with the specified key-value pairs.</span>
*<span style="color:#000000;">'''(array keys,&nbsp; array values)''' - Create new dictionary with the specified keys and values.</span>
==== <span style="color:#a52a2a;">'''Methods'''</span>  ====
*<span style="color:#000000;">'''bool Add(string key, AnyType value)''' - Adds the specified key and value to the dictionary.</span>
*<span style="color:#000000;">'''bool Add(number key, AnyType value)''' - Adds the specified key and value to the dictionary.</span>
*<span style="color:#000000;">'''Empty set_Item(string key, AnyType value)''' - Set an item based on a key and a value.</span>
*<span style="color:#000000;">'''Empty set_Item(number key, AnyType value)''' - Set an item based on a key and a value.</span>
*<span style="color:#000000;">'''AnyType get_Item(string key)''' - Get an item based on a key.</span>
*<span style="color:#000000;">'''AnyType get_Item(number key)''' - Get an item based on a key.</span>
*<span style="color:#000000;">'''AnyType TryGetValue(string key)''' - Gets the value associated with the specified key.</span>
*<span style="color:#000000;">'''AnyType TryGetValue(number key)''' - Gets the value associated with the specified key.</span>
*<span style="color:#000000;">'''bool ContainsKey(string key)''' - Determines whether the dictionary contains the specified key.</span>
*<span style="color:#000000;">'''bool ContainsKey(number key)''' - Determines whether the dictionary contains the specified key.</span>
*<span style="color:#000000;">'''bool ContainsValue(AnyType value)''' - Determines whether the dictionary contains the specified value.</span>
*<span style="color:#000000;">'''AnyType Remove(string key)''' - Remove the value with the specified key from the dictionary.</span>
*<span style="color:#000000;">'''AnyType Remove(number key)''' - Remove the value with the specified key from the dictionary.</span>
*<span style="color:#000000;">'''Empty Clear()''' - Remove all keys and values from the dictionary.</span>
*<span style="color:#000000;">'''string ToString()''' - The string representation of the object.</span>
==== <span style="color:#a52a2a;">'''Properties'''</span>  ====
*<span style="color:#000000;">'''number Count HasGetter'''&nbsp; - Gets the number of key/value pairs contained in the dictionary.</span>
*<span style="color:#000000;">'''array Keys HasGetter'''&nbsp; - Gets a list of keys.</span>
*<span style="color:#000000;">'''string ObjectTypeName HasGetter'''&nbsp; - The name of the type of object.</span>
*<span style="color:#000000;">'''array SortedKeys HasGetter'''&nbsp; - Gets a list of keys sorted by current collation.</span>
*<span style="color:#000000;">'''TypeInformation TypeInformation HasGetter'''&nbsp; - Get information about this class.</span>
*<span style="color:#000000;">'''array Values HasGetter'''&nbsp; - Gets a list of values.</span>
&nbsp;


==== <span style="color:#a52a2a;">'''Examples'''</span><br>  ====
==== <span style="color:#a52a2a;">'''Examples'''</span><br>  ====

Revision as of 08:41, 22 September 2011

Dictionary



The dictionary object

Constructors

  • () - Create a new dictionary with non-argument.
  • (params AnyType) - Create new dictionary with the specified key-value pairs.
  • (array keys "keys arrayConstant", array values "values arrayConstant") - Create new dictionary with the specified keys and values.

Methods

  • bool Add(string key "Add with specific key", AnyType value "Add with specific value") - Adds the specified key and value to the dictionary.
  • bool Add(number key "Add with specific key", AnyType value "Add with specific value") - Adds the specified key and value to the dictionary.
  • Empty Clear() - Remove all keys and values from the dictionary.
  • bool ContainsKey(string key "Check with specific key") - Determines whether the dictionary contains the specified key.
  • bool ContainsKey(number key "Check with specific key") - Determines whether the dictionary contains the specified key.
  • bool ContainsValue(AnyType value "Add with specific value") - Determines whether the dictionary contains the specified value.
  • AnyType this[] { get; }(string key "The key used to lookup the value.") - Get an item based on a key.
  • AnyType this[] { get; }(number key "The key used to lookup the value.") - Get an item based on a key.
  • AnyType Remove(string key "Check with specific key") - Remove the value with the specified key from the dictionary.
  • AnyType Remove(number key "Remove with specific key") - Remove the value with the specified key from the dictionary.
  • Empty this[] { set; }(string key "The key used to lookup the value.", AnyType value "The value to set.") - Set an item based on a key and a value.
  • Empty this[] { set; }(number key "The key used to lookup the value.", AnyType value "The value to set.") - Set an item based on a key and a value.
  • string ToString() - The string representation of the object.
  • AnyType TryGetValue(string key "Remove with specific key") - Gets the value associated with the specified key.
  • AnyType TryGetValue(number key "Remove with specific key") - Gets the value associated with the specified key.

Properties

  • number Count { get; } - Gets the number of key/value pairs contained in the dictionary.
  • array Keys { get; } - Gets a list of keys.
  • string ObjectTypeName { get; } - The name of the type of object.
  • array SortedKeys { get; } - Gets a list of keys sorted by current collation.
  • TypeInformation TypeInformation { get; } - Get information about this class.
  • array Values { get; } - Gets a list of values.


Examples

Dictionary d;
print(d);                 // {}


Dictionary d = new Dictionary();
print(d);                 // {}


Dictionary d = {"key1": 1, "key2": 2};
print(d);                 // {"key1": 1, "key2": 2}


Dictionary d = {};             // Not work, will cause error.


Dictionary d1 = new Dictionary("key_01","value01");
print(d1);                                                                      // {"key_01": sdasd}
print(d1.Add("key_02",2222));
print(d1.Add(3,"hello3333"));
print(d1.Add("key_03",{"happy",48,{"funny","sad",88}}));
print(d1);                               //          {"3": hello3333, "key_01": value01, "key_02": 2222, "key_03": {happy,48,{funny,sad,88}}}
print(d1.ContainsKey("key_01"));                                                // true
print(d1.ContainsKey(3));                                                       // true
print(d1.ContainsKey("noexist"));                                               // false
print(d1.ContainsValue("value01"));                                             // true
print(d1.ContainsValue(2222));                                                  // true
print(d1.ContainsValue({"happy",48,{"funny","sad",88}}));                       // true
print(d1.get_Item("key_01"));                                                   // value01
print(d1.get_Item(3));                                                          // hello3333
print(d1.set_Item("key01",1111));     
print(d1.set_Item(3,{3333,"string333"}));
print(d1.TryGetValue("key_01"));                                                // value01
print(d1.TryGetValue(3));                                                       // {3333,"string333"}
print(d1);                              //     {"3": {3333,string333}, "key_01": value01, "key_02": 2222, "key_03": {happy,48,{funny,sad,88}}, "key01": 1111}
print(d1.Count);                                                                // 5
print(d1.Keys);                                                                 // {key_01,key_02,3,key_03,key01}
print(d1.Values);                                                               // {value01,2222,{3333,string333},{happy,48,{funny,sad,88}},1111}
print(d1.Remove("key_01"));                                                     // value01
print(d1.Remove(3));                                                            // {3333,string333}
print(d1);                                                                      // {"key_02": 2222, "key_03": {happy,48,{funny,sad,88}}, "key01": 1111}


Dictionary d = 
{
  "key01": "value01",
  5: "value05"
}; 
print(d["key01"]);       // another way to get the values of keys
print(d[5]);             // another way to get the values of keys