如何在不使用Linq的情况下将IList <string>转换为字符串[]

Dan*_*lba 6 .net c# .net-2.0

我不确定将IList<string>(IList不实现ToArray属性)转换为string[]数组的最佳方法是什么.

我无法使用,Linq因为我正在使用.NET 2.0进行编译.任何想法都会很好.

jas*_*son 26

用途ICollection<T>.CopyTo:

string[] strings = new string[list.Count];
list.CopyTo(strings, 0);
Run Code Online (Sandbox Code Playgroud)

我不太确定我是否理解无LINQ限制?这听起来像你会用ToArray,如果IList<T>有它.但事实证明,它因为IEnumerable<T>.ToArray是上定义的扩展方法IEnumerable<T>,其中IList<T>实现了.那你为什么不用它呢?