Tutorial by Examples

Func provides a holder for parameterised anonymous functions. The leading types are the inputs and the last type is always the return value. // square a number. Func<double, double> square = (x) => { return x * x; }; // get the square root. // note how the signature matches the built ...
Immutability is common in functional programming and rare in object oriented programming. Create, for example, an address type with mutable state: public class Address () { public string Line1 { get; set; } public string Line2 { get; set; } public string City { get; set; } } ...
C# developers get a lot of null reference exceptions to deal with. F# developers don't because they have the Option type. An Option<> type (some prefer Maybe<> as a name) provides a Some and a None return type. It makes it explicit that a method may be about to return a null record. For...
A higher-order function is one that takes another function as an argument or returns a function (or both). This is commonly done with lambdas, for example when passing a predicate to a LINQ Where clause: var results = data.Where(p => p.Items == 0); The Where() clause could receive many diffe...
The System.Collections.Immutable NuGet package provides immutable collection classes. Creating and adding items var stack = ImmutableStack.Create<int>(); var stack2 = stack.Push(1); // stack is still empty, stack2 contains 1 var stack3 = stack.Push(2); // stack2 still contains only one, st...

Page 1 of 1