正如問題所述,我試圖將字符串數組的其中一個元素解析爲int變量。雖然代碼在語法方面是正確的,但是當我嘗試運行它時,出現以下錯誤消息。將字符串數組的元素解析爲int
錯誤1構建內容拋出FormatException:輸入字符串的格式不正確。 在System.Number.StringToNumber(字符串str的NumberStyles選項,NumberBuffer &數的NumberFormatInfo信息,布爾parseDecimal) 在System.Number.ParseInt32(字符串s的NumberStyles風格的NumberFormatInfo信息) 在System.Int32.Parse(字符串多個) 在TileContent.Tiles.TileLayerProcessor.Process(XmlDocument的輸入,ContentProcessorContext上下文)在C:\用戶\達倫\文件\恩德斯\ TileContent \瓷磚\ TileLayerProcessor.cs:線75
這裏是代碼導致下面的問題
foreach (string line in lines)
{
string realLine = line.Trim();
if (string.IsNullOrEmpty(line))
continue;
string[] cells = realLine.Split(' ');
for (int x = 0; x < width; x++)
{
int cellIndex = int.Parse(cells[x]);
layer.Layout[row, x] = cellIndex;
}
什麼它值得扼殺嗎? – luke 2010-10-01 13:20:29