我有这段代码:
TheString = "443,432,546,4547,4445,2,132"; //actually,about 1000 entries List<int> TheListOfIDs = new List<int>(); TheListOfLeadIDs = from string s in TheString.Split(',') select Convert.ToInt32(s)).ToList<int>();
我知道我可以使用try catch来确保转换不会引发错误,但我想知道如何在linq语句中使用TryParse来完成这项工作.
谢谢.
解决方法
TheListOfLeadIDs = (from string s in TheString.Split(',') let value = 0 where int.TryParse(s,out value) select value).ToList<int>();