原字符串
var textStr="1,2,3,4,5,6,7,8,9";
想要把textStr转换成List<int>类型
采用泛型的方式进行转换
List<int> textList = textStr.Split(',').Cast<int>().ToList();
调试的时候发现,Cast<int>()报错
System.InvalidCastException:“指定的转换无效
解决方法
List<int> textList = textStr.Split(',').Select<string, int>(x => Convert.ToInt32(x)).ToList()