string []到int [] [英] string[] to int[]

查看:69
本文介绍了string []到int []的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个字符串数组,我需要将其转换为int数组。任何

优雅的方法,除了迭代它并在每个

元素上使用int.parse()?


谢谢,

I have an array of string that I need to convert to an array of int. Any
elegant method other than iterating through it and using int.parse() on each
element?

Thanks,

推荐答案

否。


" Andrew Robinson" <是ne **** @ nospam.nospam>在消息中写道

新闻:uq ************** @ TK2MSFTNGP09.phx.gbl ...
No.

"Andrew Robinson" <ne****@nospam.nospam> wrote in message
news:uq**************@TK2MSFTNGP09.phx.gbl...
我有一个数组我需要转换为int数组的字符串。除了遍历它并在每个元素上使用int.parse()之外的任何优雅方法吗?

谢谢,
I have an array of string that I need to convert to an array of int. Any
elegant method other than iterating through it and using int.parse() on
each element?

Thanks,



在这里回答我自己的问题:


string [] input = {" 1"," 2"," 3"," 4" ;,5,6,7,8,9等。 };


int [] output = Array.ConvertAll< string,int>(input,delegate(string s){

return int.Parse(s );}};

" Andrew Robinson" <是ne **** @ nospam.nospam>在消息中写道

新闻:uq ************** @ TK2MSFTNGP09.phx.gbl ...
Going to answer my own question here:

string[] input = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };

int[] output = Array.ConvertAll<string, int>(input, delegate(string s) {
return int.Parse(s); });
"Andrew Robinson" <ne****@nospam.nospam> wrote in message
news:uq**************@TK2MSFTNGP09.phx.gbl...
我有一个数组我需要转换为int数组的字符串。除了遍历它并在每个元素上使用int.parse()之外的任何优雅方法吗?

谢谢,
I have an array of string that I need to convert to an array of int. Any
elegant method other than iterating through it and using int.parse() on
each element?

Thanks,



您是否阅读了Array.ConvertAll文档中的部分

声明:


数组元素单独传递

到转换器,转换后的元素

保存在新数组中。


如果那不是迭代那么我不知道是什么。

" Andrew Robinson" <是ne **** @ nospam.nospam>在消息中写道

新闻:************** @ TK2MSFTNGP12.phx.gbl ...
Did you read the part in the documentation for Array.ConvertAll where it
states:

The elements of array are individually passed
to the Converter, and the converted elements
are saved in the new array.

If that''s not iteration then I don''t know what is.
"Andrew Robinson" <ne****@nospam.nospam> wrote in message
news:Of**************@TK2MSFTNGP12.phx.gbl...
要回答我自己的问题这里的问题:

string [] input = {" 1"," 2"," 3"," 4"," 5"," 6"," 7" ;,8,9; } [

int [] output = Array.ConvertAll< string,int>(input,delegate(string s){
return int.Parse(s);});

" Andrew Robinson" <是ne **** @ nospam.nospam>在消息中写道
新闻:uq ************** @ TK2MSFTNGP09.phx.gbl ...
Going to answer my own question here:

string[] input = { "1", "2", "3", "4", "5", "6", "7", "8", "9" };

int[] output = Array.ConvertAll<string, int>(input, delegate(string s) {
return int.Parse(s); });
"Andrew Robinson" <ne****@nospam.nospam> wrote in message
news:uq**************@TK2MSFTNGP09.phx.gbl...
我有一个我需要的字符串数组转换为int数组。除了遍历它并在每个元素上使用int.parse()之外的任何优雅方法吗?

谢谢,
I have an array of string that I need to convert to an array of int. Any
elegant method other than iterating through it and using int.parse() on
each element?

Thanks,




这篇关于string []到int []的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆