拆分字符串,将 ToList<int>() 转换为一行 [英] Split string, convert ToList&lt;int&gt;() in one line

查看:30
本文介绍了拆分字符串,将 ToList<int>() 转换为一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含数字的字符串

I have a string that has numbers

string sNumbers = "1,2,3,4,5";

我可以将其拆分然后将其转换为 List

I can split it then convert it to List<int>

sNumbers.Split( new[] { ',' } ).ToList<int>();

如何将字符串数组转换为整数列表?这样我就可以将 string[] 转换为 IEnumerable

How can I convert string array to integer list? So that I'll be able to convert string[] to IEnumerable

推荐答案

var numbers = sNumbers.Split(',').Select(Int32.Parse).ToList();

这篇关于拆分字符串,将 ToList<int>() 转换为一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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