GNOME Bugzilla – Bug 562063
Cannot use typeof inside foreach
Last modified: 2010-05-27 21:16:28 UTC
Please describe the problem: Cannot use typeof inside foreach Steps to reproduce: using GLib; public class Test { public static void main(string[] args){ var array = new string[10] { "0", "1", "2"}; foreach( string item in array ){ stdout.printf(typeof(item)); } Actual results: Main.vala:10.46-10.49: error: The type name `item' could not be found stdout.printf(typeof(item)); ^^^^ Expected results: Does this happen every time? Other information:
typeof returns the GLib.Type of a static type, for example typeof(string) returns the GLib.Type for strings. However, it cannot be used to return the static type of a variable, and that's itentional. You can retrieve the dynamic type of an object by using the get_type() method, this will only work for GObject derived types, though.
*** Bug 573075 has been marked as a duplicate of this bug. ***