c# .net Adsense ADO.NET Linq Viruses/security asp.net MVC JQuery Angular-js Node-js SEO Java C++ SQL API Networking vb.net .Net Css JavaScript Generics c#.Net entity framework HTML Website host Website Construction Guide HTTP tutorial W3C tutorial Web Services JSON Psychology Ionic framework Angular ReactJS Python Computer Android
c# .net

How to convert String array to List using C#?

| | CSharp

In this articleI will explain how to convert String array to List using C#. we can achieve byusing .ToList() on array types, this seems to be available only in .Net 3.5+.  

using System.Collections.Generic;

static void Main(string[] args)

        {

            try

            {

                string[] array = { "hi", "how", "are", "you", "?" };

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

                foreach (string item in list)

               {

                   Console.WriteLine(item);

               }

             }

            catch(Exception ex) {

                Console.WriteLine(ex.ToString());

            }

             Console.ReadLine();

        }

Output: 

Hi

How

Are

You

?