我怎么能转换逗号分隔字符串转换成一个List< INT> [英] How can I convert comma separated string into a List<int>

查看:164
本文介绍了我怎么能转换逗号分隔字符串转换成一个List< INT>的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

string tags = "9,3,12,43,2"

List<int> TagIds = tags.Split(',');

这不工作导致拆分方法返回一个字符串[]

This doesnt work cause the split method returns a string[]

请帮忙。

推荐答案

下面是这样做的一种方式:

Here is one way of doing it:

List<int> TagIds = tags.Split(',').Select(int.Parse).ToList();

这篇关于我怎么能转换逗号分隔字符串转换成一个List&LT; INT&GT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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