How to convert list<int> to int[] in C#

1 Answer

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

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

            list.Add(1);
            list.Add(23);
            list.Add(100);

            arr = list.ToArray();

            foreach (var item in arr)
                Console.Write(item.ToString() + " ");
        }
    }
}

/*
run:
   
1 23 100
  
*/

 



answered Feb 12, 2016 by avibootz
edited Feb 17, 2016 by avibootz

Related questions

1 answer 106 views
2 answers 142 views
1 answer 156 views
156 views asked Feb 11, 2024 by avibootz
1 answer 125 views
125 views asked Jul 23, 2023 by avibootz
1 answer 165 views
1 answer 147 views
147 views asked May 25, 2019 by avibootz
...