aboutsummaryrefslogtreecommitdiffstats
path: root/reference/csharp/eina/src/eina_array.cs
blob: 9cf9d5497017eebc390b0637fe35c24ed823aac5 (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
/*
 * Eina Array examples.
 *
 * These examples demonstrate how to work with Eina_array data and methods.
 * We use a simple array of strings to initialise our Eina_array before
 * performing various mutations and printing the results.
 */

using System;

public class Example
{
    static Eina.Array<string> CreateArray()
    {
        // some content to populate our array
        string[] names =
        {
            "helo", "hera", "starbuck", "kat", "boomer",
            "hotdog", "longshot", "jammer", "crashdown", "hardball",
            "duck", "racetrack", "apolo", "husker", "freaker",
            "skulls", "bulldog", "flat top", "hammerhead", "gonzo"
        };

        // set up an array with a growth step to give a little headroom
        var array = new Eina.Array<string>(25u);

        foreach (string name in names)
            array.Push(name);

        return array;
    }

    static bool ItemRemoveCb(string name)
    {
        // let's keep any strings that are no more than 7 characters long
        if (name.Length <= 7)
            return false;
        return true;
    }

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

        var array = CreateArray();

        // show the contents of our array
        Console.WriteLine("Array count: {0}", array.Count());
        Console.WriteLine("Array contents:");
        foreach(string name in array)
        {
            // content is strings so we simply print the data
            Console.WriteLine("  {0}", name);
        }

        // access a specific item in the array
        Console.WriteLine("Top gun: {0}", array[2]);

        // update a single item in the array
        array[17] = "flattop";
        // update the array removing items that match the ItemRemoveCb criteria
        // array.RemoveAll(ItemRemoveCb); // TODO: FIXME

        // print the new contents of our array
        Console.WriteLine("New array count: {0}", array.Length);
        Console.WriteLine("New array contents:");
        foreach(string name in array)
            Console.WriteLine("  {0}", name);

        array.Dispose();

        Efl.All.Shutdown();
    }
}