开发者

what is the best way in C# to convert string into int[] [duplicate]

This question already has answers here: Closed 11 years ago.

Possible Duplica开发者_如何学JAVAte:

Split string, convert ToList<int>() in one line…

i have a string that looks like this.

string s = "1,6,4,3,5,7,4";

and i want to convert this into an array of integers.

what is the best and fastest way of doing this in C#?


use split method.

int[] array = s.Split(',').Select(str => int.Parse(str)).ToArray();

Hmm, don't know if it is fastest way, however it is the simplest way :)


Hope this helps :)

int[] i = Array.ConvertAll(s.Split(','), new Converter<string, int>(delegate (string str) { return int.Parse(str); } ));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜