examples/reference/csharp/eina/src/eina_array.cs

76 lines
2.1 KiB
C#

/*
* 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();
}
}