summaryrefslogtreecommitdiff
path: root/reference/csharp/eina/src/eina_list.cs
diff options
context:
space:
mode:
authorVitor Sousa <vitorsousasilva@gmail.com>2018-02-16 15:24:11 -0200
committerVitor Sousa <vitorsousasilva@gmail.com>2018-02-16 15:24:11 -0200
commitbc174ae1159bf024877b84bbfad2465ab7c9bf64 (patch)
tree7c00c6f1099876501642175287f02fd109674e0c /reference/csharp/eina/src/eina_list.cs
parent66dd51dc4baa3db406a751d024ec4c812b9b30d7 (diff)
eina_mono: add first reference examples for Eina C# binding
Diffstat (limited to 'reference/csharp/eina/src/eina_list.cs')
-rw-r--r--reference/csharp/eina/src/eina_list.cs71
1 files changed, 71 insertions, 0 deletions
diff --git a/reference/csharp/eina/src/eina_list.cs b/reference/csharp/eina/src/eina_list.cs
new file mode 100644
index 0000000..b1ddfef
--- /dev/null
+++ b/reference/csharp/eina/src/eina_list.cs
@@ -0,0 +1,71 @@
1
2/*
3 * Eina List examples.
4 *
5 * These examples demonstrate how to work with eina_list data and methods.
6 * We create a simple list of names by appending strings to an empty list
7 * and then run various mutations and print each result.
8 */
9
10using System;
11using System.Linq;
12
13public class Example
14{
15 static eina.List<string> CreateList()
16 {
17 var list = new eina.List<string>();
18
19 list.Append("Adama");
20 list.Append("Baltar");
21 list.Append("Roslin");
22
23 return list;
24 }
25
26 public static void Main()
27 {
28 efl.All.Init();
29
30 var list = CreateList();
31
32 // print our list with a simple foreach
33 Console.WriteLine("List size: {0}", list.Count());
34 Console.WriteLine("List content:");
35 foreach(string item in list)
36 Console.WriteLine(" {0}", item);
37
38 // insert some more elements
39 list.Prepend("Cain");
40// list.PrependRelative("Tigh", "Baltar"); // TODO: missing
41
42 Console.WriteLine("New list content:");
43 foreach(string item in list)
44 Console.WriteLine(" {0}", item);
45
46 // promote an item to the top of the list
47 // TODO: implement ?
48// list.PromoteList(list.NthList(1));
49// list.Remove("Cain");
50//
51// Console.WriteLine("List content after promotion:");
52// foreach(string item in list)
53// Console.WriteLine(" {0}", item);
54
55 // we can sort the list with any callback
56// list.Sort((string strA, string strB) => { return strA.Compare(strB); }); // TODO: FIXME custom sort
57 list.Sort();
58 Console.WriteLine("List content sorted:");
59 foreach(string item in list)
60 Console.WriteLine(" {0}", item);
61
62 // and foreach can be in reverse too
63 Console.WriteLine("List content reverse sorted:");
64 foreach(string item in list.Reverse())
65 Console.WriteLine(" {0}", item);
66
67 list.Dispose();
68
69 efl.All.Shutdown();
70 }
71}