[Vala] Gee ArrayList item question



Hi,
Probably a silly question from a permanent newb. See this code:
----
using Gee;

int main() {

  var L = new ArrayList<int>();

  L.add(10);
  L.add(20);
  L.add(30);
  L.insert (2, 50);
  int x=0;
  foreach (int i in L) {
    //This line shows indexes 0,1,2,3
    stdout.printf ("%d and %d\n", i, L.index_of(i));
    /*
    This line, using an int x, shows only -1 each time.
    --> stdout.printf ("%d and %d\n", i, L.index_of(x));
    --> x++;

    This suggests to me that "int i" is not an int - it's
    an "item" and that's also supported by index_of because
    it accepts an "item".
    So, there are ints and there are ints... :O

    */
  }
  return 0;
}

---

The remarks show the mystery. What *is* the "i" variable (declared in
the foreach)? It looks like an "int", but there's that L.index_of
method that takes an "item". So, I added that "int x" just to test it;
and it does break things.

What is coming out of that foreach? What type is "i" really?


\d


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