列出的int我有這樣一段代碼:字符串整型成與一個的TryParse
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進行操作。
謝謝。
你有什麼期望時,發現非int值的情況發生,用0替換它,忽略它,拋出一個錯誤? – ilivewithian 2012-04-21 12:27:32