2014-01-23 65 views
1

我想要顯示當我的List的結果= 1時從List獲得的數據。我需要獲得FileName,TitleHotspotID在C#中顯示來自列表的數據

有人可以幫我嗎?我需要幫助的部分在我的代碼的最後部分。

這裏是代碼:

private void PerformSheetLink(String hotspotID, Int32 fileRec) 
    { 
     string nomenclature = dataLayer.GetNomenclature(fileRec, hotspotID); 
     string pattern = @"\((?<ProjectRec>\d+(?:_)?\d*?)*\,(?<FileName>[^,]*)\,(?<HotspotID>[^)]*)\)"; 
     Regex regex = new Regex(pattern, RegexOptions.Compiled); 
     Match m = regex.Match(nomenclature); 

     //Multiple numenclature exist   
     if (regex.Matches(nomenclature).Count > 1) 
     { 
      List<P2Trace> linkList = new List<P2Trace>(); 
      string fileName, hotspot, title;     
      MatchCollection mc = regex.Matches(nomenclature); 
      foreach (Match match in mc) 
      { 
       //This match has a Single Project 
       GroupCollection gc = match.Groups; 
       if (gc["ProjectRec"].Captures.Count == 1) 
       { 
        if ((int)cbModel.SelectedValue == Int32.Parse(gc["ProjectRec"].Value)) 
        { 
         fileName = String.Format("{0}.cgm", gc["FileName"].Value); 
         title = dataLayer.GetSheetTitle(fileName); 
         hotspot = FixHotspotID(gc["HotspotID"].Value); 
         linkList.Add(new P2Trace { FileName = fileName, HotspotID = hotspot, Title = title }); 
        } 
       } 
       else 
       { 
        //This match has Multiple Projects 
        List<Int32> pRecs = GetProjectRecsInList(gc["ProjectRec"].Captures); 
        if (pRecs.Contains((int)cbModel.SelectedValue)) 
        { 
         foreach (Int32 projectRecNo in pRecs) 
         { 
          if (projectRecNo == (int)cbModel.SelectedValue) 
          { 
           fileName = String.Format("{0}.cgm", gc["FileName"].Value); 
           title = dataLayer.GetSheetTitle(fileName); 
           hotspot = FixHotspotID(gc["HotspotID"].Value); 
           linkList.Add(new P2Trace { FileName = fileName, HotspotID = hotspot, Title = title }); 
          } 
         } 
        } 
       } 
      } 
      //Link found and collected, perform jump 
      if (linkList.Count == 1) 
      { 
       p2Trace.FileName = linkList. ????? 
       p2Trace.Title = linkList. ?????? 
       p2Trace.HotspotID= linkList. ?????? 
       jumpTo(p2Trace.FileName, p2Trace.Titel, p2Trace.HotspotID); 

      } 
+0

這是你的意圖,只叫'jumpTo'如果你準確地找到一個匹配?如果發現兩場比賽會發生什麼? –

+0

我已經照顧過那部分,我只是沒有發佈代碼 –

回答

1
p2Trace.FileName = linkList[0].FileName; 
p2Trace.Title = linkList[0].Title; 
p2Trace.HotspotID = linkList[0].HotspotID; 
0

嘗試......

if (linkList.Count == 1) 
    { 
var firstItem = linkList[0]; 
     p2Trace.FileName = firstItem.FileName; 
     p2Trace.Title = firstItem.Title; 
     p2Trace.HotspotID= firstItem.HostspotID; 
     jumpTo(p2Trace.FileName, p2Trace.Titel, p2Trace.HotspotID); 

    } 
+0

工作正常。謝謝您的幫助 –

相關問題