0

public Card deal_one_card(List<Card> cards)
{
if (cards.Count() == 0)
{
return null;
}
return cards.RemoveAt(0);

    }


    I am getting an error when I run this function "Cannot implicitly convert type 'void' to 'Poker.Card'   

    Can somebody help with me this? 

    Thanks in advance.
3
Contributors
3
Replies
4
Views
5 Years
Discussion Span
Last Post by Dani
0

RemoveAt has no return value (void is not a return value) but you try to return it in your last line. If you want to return and remove the first card, you'll need to place it in a temp variable, remove it from the list, then return the temp variable:

public Card deal_one_card(List<Cards> cards) {
    if (cards.Count() == 0) {
        return null;
    }

    Card result = cards[0];
    cards.RemoveAt(0);
    return result;
}

Edited by pyTony: fixed formatting

0

public Card deal_one_card(List<Cards> cards) {
if (cards.Count() == 0) {
return null;
}

    Card result = cards[0];
    cards.RemoveAt(0);
    return result;
}

I do not like the new code method.

0

You just need to indent by at least four spaces, or hit tab. Also be sure to leave a blank line above and below your code snippet. The preview shows you what it will look like. Sorry to hijack your thread!!!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.