简体   繁体   中英

How do I split a string to a LinkedList<int>?

I have a string like this:

string myS = "20,        21,        22,        23,        24"

I want to get this:

LinkedList<int> myLL = new LinkedList<int>();

I tried this:

myLL = (LinkedList<int>)myS.Split(',').Select(n => int.Parse(n.Trim()));

It does not work, throw conversion error, what do?

使用LinkedList<T>(IEnumerable<T> source)构造函数而不是强制转换:

var myLL = new LinkedList<int>(myS.Split(',').Select(n => int.Parse(n.Trim()));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM