ConsListmyList = ConsList .Empty.Cons(3).Cons(2).Cons(1); int firstElement = myList.Head; // returns 1
ConsListIn both examples, we use the ConsList class to create a new linked list and add elements to it using the Cons method. We then retrieve the first element of the list using the Head method. The ConsList class is part of the FunctionalHelpers package library.myList = ConsList .Empty; for (int i = 0; i < 5; i++) { myList = myList.Cons("Element " + i); } string firstElement = myList.Head; // returns "Element 0"