How to convert an array of strings to List using Linq in C#

1 Answer

0 votes
using System;
using System.Collections.Generic;
using System.Linq;

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

            List<string> list = arr.ToList();

            foreach (string s in list)
                Console.WriteLine(s);
        }
    }
}

/*
run:

c#
java
c++
c

*/

 



answered Jan 6, 2017 by avibootz
...