Skip to content
This repository was archived by the owner on Nov 13, 2018. It is now read-only.

Methods

Jordan Kniest edited this page May 28, 2017 · 13 revisions

Here you can find explanations and examples for all collection methods.


Reduce

The reduce method converts a collection into some other type. For example it could be used to sum the items (converting the collection to a single integer)

Structure:

public T Reduce<T>(ReduceCallback<T> callable, T initial);

Example:

// Create a new collection with three integer values (10, 20, 30)
var collection = new Collection<int>(10, 20, 30);

// Reduce this collection to a single integer value
var result = collection.Reduce((value, item) => {
    return value + item; 
}, 0);

// Print the result to the console
Console.Write(result); // The result is: 60

All

Return all items as an array. It is in fact an alias for the 'ToArray' method.

Structure:

public TList[] All();

Example:

// Create a new collection with three integer values (10, 20, 30)
var collection = new Collection<int>(10, 20, 30);

// Request all items
var result = collection.All();

// Print the first item to the console
Console.Write(result[0]); // The result is: 10

Clone this wiki locally