可能重复:
错误无法从“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();