3 | | See also [http://cobra-language.com/forums/viewtopic.php?f=4&t=15 Cobra Forums Differences with C#] |
| 3 | == Illustrated == |
| 4 | |
| 5 | {{{ |
| 6 | #!cobra |
| 7 | # Cobra |
| 8 | d = {'a': 1, 'b': 2} |
| 9 | assert d['a'] == 1 and d['b'] == 2 |
| 10 | for key, value in d |
| 11 | print '[key] = [value]' # string interpolation |
| 12 | }}} |
| 13 | |
| 14 | {{{ |
| 15 | // C# |
| 16 | var dictionary = new Dictionary<string, int> { {"a", 1}, {"b", 2} }; |
| 17 | Assert.IsTrue(dictionary["a"] == 1 && dictionary["b"] == 2); |
| 18 | foreach (var key in dictionary.Keys) |
| 19 | { |
| 20 | var value = dictionary[key]; |
| 21 | Debug.WriteLine(string.Format("{0} == {1}", key, value)); |
| 22 | } |
| 23 | }}} |
| 24 | |
| 25 | credit: http://fir3pho3nixx.blogspot.com/2011/01/when-c-is-not-enough.html |
| 26 | |
| 27 | |
| 28 | == Quick Reference == |