string[] rounds = cols[5].Split('|');
foreach (string round in rounds)
{
//splitting each round on "^"
string[] msText = round.Split('^');
//create a new list in text file
List<MatchupModel> ms = new List<MatchupModel>();
foreach (string matchupModelTextId in msText)
{
// this is the line on which I am getting the error
ms.Add(matchups.Where(x => x.Id == int.Parse(matchupModelTextId)).First());
}
tm.Rounds.Add(ms);
}
答案 0 :(得分:0)
试试这个 - 看看matchupModelTextId
是否可以解释为一个整数,只有它可以,让它添加匹配;
foreach (string matchupModelTextId in msText)
{
int matchupId;
if (int.tryParse(matchupModelTextId, out matchupId)) {
ms.Add(matchups.Where(x => x.Id == matchupId).First());
}
}