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 97 views
2 answers 132 views
1 answer 138 views
138 views asked Feb 11, 2024 by avibootz
1 answer 114 views
114 views asked Jul 23, 2023 by avibootz
1 answer 149 views
1 answer 136 views
136 views asked May 25, 2019 by avibootz
...