【发布时间】:2011-05-29 18:53:48
【问题描述】:
我需要一种简单的方法将 List<int> 转换为 string 数组。
我有:
var the_list = new List<int>();
the_list.Add(1);
the_list.Add(2);
the_list.Add(3);
string[] the_array = new string[the_list.Count];
for(var i = 0 ; i < the_array.Count; ++i)
the_array[i] = the_list[i].ToString();
...这对我来说看起来很丑。
有没有更简单的方法?
注意:我正在寻找一种更简单的方法 - 不一定是更快的方法。
【问题讨论】:
-
这是最有效的方法,除非数组中有很多重复的元素。当然,这并不意味着它一定是最简单的方法。
-
您似乎在问两个不同的问题:什么更有效,哪个更容易。 IMO,这两个问题的答案是不同的:)
-
@Brian:我在问哪个更容易 - 很抱歉造成混乱。