72 lines
2.0 KiB
C#
72 lines
2.0 KiB
C#
|
|
/*
|
|
* Eina List examples.
|
|
*
|
|
* These examples demonstrate how to work with Eina_list data and methods.
|
|
* We create a simple list of names by appending strings to an empty list
|
|
* and then run various mutations and print each result.
|
|
*/
|
|
|
|
using System;
|
|
using System.Linq;
|
|
|
|
public class Example
|
|
{
|
|
static Eina.List<string> CreateList()
|
|
{
|
|
var list = new Eina.List<string>();
|
|
|
|
list.Append("Adama");
|
|
list.Append("Baltar");
|
|
list.Append("Roslin");
|
|
|
|
return list;
|
|
}
|
|
|
|
public static void Main()
|
|
{
|
|
Efl.All.Init();
|
|
|
|
var list = CreateList();
|
|
|
|
// print our list with a simple foreach
|
|
Console.WriteLine("List size: {0}", list.Count());
|
|
Console.WriteLine("List content:");
|
|
foreach(string item in list)
|
|
Console.WriteLine(" {0}", item);
|
|
|
|
// insert some more elements
|
|
list.Prepend("Cain");
|
|
// list.PrependRelative("Tigh", "Baltar"); // TODO: missing
|
|
|
|
Console.WriteLine("New list content:");
|
|
foreach(string item in list)
|
|
Console.WriteLine(" {0}", item);
|
|
|
|
// promote an item to the top of the list
|
|
// TODO: implement ?
|
|
// list.PromoteList(list.NthList(1));
|
|
// list.Remove("Cain");
|
|
//
|
|
// Console.WriteLine("List content after promotion:");
|
|
// foreach(string item in list)
|
|
// Console.WriteLine(" {0}", item);
|
|
|
|
// we can sort the list with any callback
|
|
// list.Sort((string strA, string strB) => { return strA.Compare(strB); }); // TODO: FIXME custom sort
|
|
list.Sort();
|
|
Console.WriteLine("List content sorted:");
|
|
foreach(string item in list)
|
|
Console.WriteLine(" {0}", item);
|
|
|
|
// and foreach can be in reverse too
|
|
Console.WriteLine("List content reverse sorted:");
|
|
foreach(string item in list.Reverse())
|
|
Console.WriteLine(" {0}", item);
|
|
|
|
list.Dispose();
|
|
|
|
Efl.All.Shutdown();
|
|
}
|
|
}
|