2017-10-22 11 views
-2
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); 
} 
+2

(https://msdn.microsoft.com/en-us/library/b3h1hf19(V = vs.110)の.aspx)文字列である場合に発生することができ正しい形式ではありません(セクション「例外」および「備考」を参照)。 matchupModelTextIdに数字が含まれていることを確認しましたか? – Marius

答えて

0

これを試してください - matchupModelTextIdは、マッチアップを追加できる場合に限り、整数として解釈できるかどうかを確認してください。 [MSDN Int.Parseドキュメント]によれば

foreach (string matchupModelTextId in msText) 
{ 
    int matchupId; 
    if (int.tryParse(matchupModelTextId, out matchupId)) { 
     ms.Add(matchups.Where(x => x.Id == matchupId).First()); 
    } 
} 
+1

本当にありがとう、私は魅力のように働いた。あなたは私のプロジェクト全体を書き直すことから私を救った:) –

+0

問題なし - 助けてうれしい! –

関連する問題