c# map list code example

Example 1: f# list map function

let squares = [2; 4; 6; 8]
              |> List.map (fun n -> n * n)
// val squares : int list = [4; 16; 36; 64]

Example 2: f# list map function

let f = fun n -> n * n
let squares = [2; 4; 6; 8] |> List.map f
// val squares : int list = [4; 16; 36; 64]

Example 3: f# list map function

let toUpper = fun c -> System.Char.ToUpper(c)
let allcaps = "sesquipedalian"
              |> String.map toUpper
// val allcaps : string = "SESQUIPEDALIAN"

Example 4: c# sort list

using System;

class Program
{
    static void Main()
    {
        string[] colors = new string[]
        {
            "orange",
            "blue",
            "yellow",
            "aqua",
            "red"
        };
        // Call Array.Sort method.
        Array.Sort(colors);
        foreach (string color in colors)
        {
            Console.WriteLine(color);
        }
    }
}