How to convert a List to array of strings in C#

1 Answer

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

namespace ConsoleApplication_C_Sharp
{
    class Program
    {
        static void Main(string[] args)
        {
            List<string> list = new List<string>();

            list.Add("c#");
            list.Add("java");
            list.Add("c++");

            string[] arr = list.ToArray();

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

/*
run:

c#
java
c++

*/

 



answered Jan 6, 2017 by avibootz

Related questions

1 answer 172 views
1 answer 206 views
1 answer 151 views
2 answers 132 views
1 answer 149 views
1 answer 147 views
...