如何在其他列表c#中移动堆栈列表?

如何在其他列表c#中移动堆栈列表?,c#,C#,我在做纸牌游戏 我需要帮助将几张牌从一堆移到另一堆 我可以将一张牌移到另一张牌堆中,但我不知道如何更改,因为我使用的是堆栈列表 那么,如何在第一个索引之外检查另一个索引呢 // valid card at to pile public bool TryPushCardsOnPile(Card card, int index) { Stack<Card> pile = piles[index]; if (pile.Count

我在做纸牌游戏

我需要帮助将几张牌从一堆移到另一堆

我可以将一张牌移到另一张牌堆中,但我不知道如何更改,因为我使用的是堆栈列表

那么,如何在第一个索引之外检查另一个索引呢

       // valid card at to pile
    public bool TryPushCardsOnPile(Card card, int index)
    {
        Stack<Card> pile = piles[index];
        if (pile.Count() == 0)
        {
            return (card.getRank() == CardRank.King);
        }
        Card topPile = piles[index].Peek();

        if (!topPile.IsVisible())
        {
            return false;
        }
        return (card.IsRed() != topPile.IsRed()) && (card.getRank() == topPile.getRank() - 1);
    }

谢谢

虽然使用列表甚至自定义链表可能是更好的选择,但将项目块从一个堆栈移动到另一个堆栈很容易:全部弹出、反转、推送到另一个堆栈:

 var items = sourceStack.Take(4).Reverse().ToList();
 items.ForEach(x => destinationStack.Push(x));

请简化你的问题,并张贴一个好的,清楚地表明你正在努力做什么。准确地解释代码现在做了什么,您希望它做什么,以及您遇到的具体问题。不清楚为什么使用堆栈对您来说是一个问题,也不清楚为什么如果是一个问题,您不只是使用不同的数据结构(例如,某种类型的普通列表),在其中可以在任意位置添加/删除元素。请阅读并阅读。你需要描述一个(明确的)问题,并提出一个明确的问题,以得到一个好的答案<代码>我需要帮助不是问题
 var items = sourceStack.Take(4).Reverse().ToList();
 items.ForEach(x => destinationStack.Push(x));