Convert IList to array in C#

前端 未结 4 1994
后悔当初
后悔当初 2021-01-08 00:24

I want to convert IList to array: Please see my code:

IList list = new ArrayList();
list.Add(1);
Array array = new Array[list.Count];
list.CopyTo(array, 0);
         


        
4条回答
  •  余生分开走
    2021-01-08 00:58

    probably the most compact solution is this:

    Enumerable.Range(0, list.Count).Select(i => list[i]).ToArray();

提交回复
热议问题