2012-06-16 31 views
-4

可能重複:
Error cannot convert from 'System.Collections.Generic.List<GameLibrary.Cards.Card>' to 'GameLibrary.Cards.Card'更新的誤差不能從 'System.Collections.Generic.List <GameLibrary.Cards.Card>' 轉換爲 'GameLibrary.Cards.Card'

private List<List<Card>> GetCardMatchesInHand() 
    { 
     List<Card> list4; 
     List<List<Card>> list = new List<List<Card>>(); 
     List<GameLibrary.Cards.Card> list2 = new List<GameLibrary.Cards.Card>() 
     List<Card> list3 = new List<Card>(); 
     list4 = new List<Card> { 
      list2, 
      list3, 
      list4 
     }; 
     List<Card> list5 = this.Cards.ToList<Card>(); 
     using (List<Card>.Enumerator enumerator = this.Cards.GetEnumerator()) 
     { 
      Predicate<Card> match = null; 
      Predicate<Card> predicate2 = null; 
      Predicate<Card> predicate3 = null; 
      Predicate<Card> predicate4 = null; 
      Predicate<Card> predicate5 = null; 
      Card c; 
      while (enumerator.MoveNext()) 
      { 
       c = enumerator.Current; 
       list5.Remove(c); 
       if (match == null) 
       { 
        match = element => element.CardValue == c.CardValue; 
       } 
       Card item = list5.Find(match); 
       if (item != null) 
       { 
        if (predicate2 == null) 
        { 
         predicate2 = element => element.CardValue == c.CardValue; 
        } 
        if (list2.Exists(predicate2)) 
        { 
         if (predicate3 == null) 
         { 
          predicate3 = element => element.CardValue == c.CardValue; 
         } 
         item = list2.Find(predicate3); 
         list2.Remove(item); 
         list3.Add(c); 
        } 
        else 
        { 
         if (predicate4 == null) 
         { 
          predicate4 = element => element.CardValue == c.CardValue; 
         } 
         if (list3.Exists(predicate4)) 
         { 
          if (predicate5 == null) 
          { 
           predicate5 = element => element.CardValue == c.CardValue; 
          } 
          item = list3.Find(predicate5); 
          list3.Remove(item); 
          list4.Add(c); 
         } 
         else 
         { 
          list2.Add(c); 
         } 
        } 
       } 
      } 
     } 
     return list; 
    } 

我在這行「list2,list3,list4」上說錯誤。現在爲什麼我得到這個錯誤?這是現在發佈的完整代碼。 也許現在你可以看到我試圖做什麼。 也使用它來檢查列表中的匹配。

List<List<Card>> cardMatches = this.GetCardMatchesInHand(); 
+0

剛剛發佈完整的代碼仍然沒有解釋你想要做什麼。您之前的問題之前的所有評論仍然適用。 –

+0

不要因爲更新而重新發布您的問題。更新您的原始問題。 –

回答

0

變化

list4 = new List<Card> { 

list1 = new List<List<Card>> { 
0

變量list2list3list4持有的卡列表,所以你不能使包含它們的卡的列表。他們是卡片列表,而不是卡片。

列表保存起來會卡列表的列表:

list4 = new List<List<Card>> { 
    list2, 
    list3, 
    list4 
}; 
相關問題