Re: [Vala] No foreach through HashMap<string, string> ?




________________________________
From: Gilzad Hamuni <gilli4 gmx net>
Sent: Monday, 7 September 2015, 18:10
Subject: [Vala] No foreach through HashMap<string, string> ?

I'm not sure if I've read it somewhere already, so I have to ask again (sorry). Isn't it possible to iterate 
though a Gee.HashMap if its key and value are of the same type?

Having

Gee.HashMap<string, string> foo = new Gee.HashMap<string, string>();

//I can't do

foreach(Gee.Map.Entry<string, string> bar in foo){}

..because I get the error:

Cannot convert from `int' to `string'
       foreach(Gee.Map.Entry <string, string> bar in foo)
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^



Take a look at https://wiki.gnome.org/Projects/Vala/GeeSamples#Map_Example
Also type inference may be your friend here and save you a bit of typing.

So 


Gee.HashMap<string, string> foo = new Gee.HashMap<string, string>();

would be

var foo = new Gee.HashMap<string, string>();


and


foreach(Gee.Map.Entry<string, string> bar in foo){}
would be


foreach(var bar in foo.entries){}


Hope that helps,
Al


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]