2017-10-22 1 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

아무 문제 없어 - 도와 줘서 기쁩니다! –

관련 문제