C# Lists 👷🏼♂️👷🏼♀️
using
using System.Collections;
using System.Collections.Generics;
Creation, Adding, Looping
var tokens = new List<string>();
tokens.add(token);
foreach(string token in tokens) // using foreach
{
Console.WriteLine(token);
}
tokens.ForEach(t => Console.WriteLine(t)); // using the ForEach method
tokens[1]; // access item at index 1
Creating a pre populated list
var myList = new () { 1, 2, 3, 4 };
Sorting
deviceList.sort( (x, y) => String.Compare(x.Hierarchy, y.Hierarchy) );
Cool Code
Just seen this nice bit of code written by Neil... (it's a little bit functional)
List<string> ids = ListGrid.GetSelection();
List<Guid> newIds = ids.ConvertAll(id => new Guid(id));