aboutsummaryrefslogtreecommitdiffstats
path: root/reference/csharp/eina/src/eina_iterator.cs
blob: 54f02ffadadcdc91668d3fcb4d678feda99d5fa6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78

/*
 * Eina Iterator examples.
 *
 * These examples demonstrate how to work with Eina_iterator methods.
 * Both an Eina_list and an Eina_array are created and an iterator obtained
 * for both. You can see how we can use iterators irrespective of the source
 * and also that there are different ways to work with iterating content.
 */

using System;

public class Example
{
    static void PrintIterator(Eina.Iterator<string> it)
    {
        Console.WriteLine("--iterator start--");
        foreach(string s in it)
            Console.WriteLine(s);
        Console.WriteLine("-- iterator end --");
    }

    static Eina.Array<string> CreateArray()
    {
        string[] strings =
        {
            "name strings",
            "husker",
            "starbuck",
            "boomer"
        };

        var array = new Eina.Array<string>(4u);

        foreach (string s in strings)
            array.Push(s);

        return array;
    }

    static Eina.List<string> CreateList()
    {
        string[] more_strings = {
            "sentence strings",
            "what do your hear?",
            "nothing but the rain",
            "then grab your gun and bring the cat in"
        };

        var list = new Eina.List<string>();

        foreach (string s in more_strings)
            list.Append(s);

        return list;
    }

    public static void Main()
    {
        Efl.All.Init();

        // create an Eina.Array and iterate through it's contents
        var array = CreateArray();
        var it = array.GetIterator();
        PrintIterator(it);
        it.Dispose();
        array.Dispose();

        // perform the same iteration with an Eina.List
        var list = CreateList();
        it = list.GetIterator();
        PrintIterator(it);
        it.Dispose();
        list.Dispose();

        Efl.All.Shutdown();
    }
}