Using a lambda to write out words and their lengths - CSharp Custom Type

CSharp examples for Custom Type:Lambda

Description

Using a lambda to write out words and their lengths

Demo Code



using System;/*from   www .j a  va  2  s .c  om*/
using System.Collections.Generic;

class Program
{
    static void Main(string[] args)
    {
        List<int> numbers = new List<int>() { 1, 2, 3, 4, 5, 6, 7, 8, 9, 0 };
        int[] numArray = numbers.ToArray();
        List<string> words = new List<string> { "one", "two", "three", "four", "five" };

        int count = 0;
        List<int> wordLengths = new List<int>();
        wordLengths.ForEach(n =>
        {
            Console.Write("\t{0} is ", words[count]);
            Console.WriteLine("{0} chars long.", n);
            count++;
        });

    }
}

Related Tutorials