How to use array.ToLookup() to get string item with specific length from string array in C#

1 Answer

0 votes
using System;
using System.Linq;

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] array = { "php", "c#", "c++", "java", "sql" };

            var lookup = array.ToLookup(item => item.Length);

            foreach (string s in lookup[3])
                Console.WriteLine(s);
        }
    }
}


/*
run:
     
php
c++
sql
 
*/

 



answered Feb 21, 2017 by avibootz
...