0

hey i want to return my whole string array but the program wants me to specify one

public string CreateCards( string[] Cards)
        {
            Cards = new string[52];
            for (int a = 0; a <= 51; a++)
            {
                if (a <= 12)
                {
                    Cards[a] = "   Hjärter " + (a+1).ToString();
                }
                if (a > 12 && a <= 25)
                {
                    Cards[a] = "   Ruter " + (a-12).ToString();
                }
                if (a > 25 && a <= 38)
                {
                    Cards[a] = "   Spader " + (a-25).ToString();
                }
                if (a > 38)
                {
                    Cards[a] = "   Klöver " + (a-38).ToString();
                }
            }
            return Cards;  //i get wrong here saying i need to return an array and Cards[] wont work
            //because they expect a value
        }

i want to call this from another part of the program which you input a string array [52] and my method creates cards for it
Thank you for answers :)

2
Contributors
4
Replies
7
Views
4 Years
Discussion Span
Last Post by Dendei
0
public string[] CreateCards( string[] Cards)
        {
            Cards = new string[52];
            for (int a = 0; a <= 51; a++)
            {
                if (a <= 12)
                {
                    Cards[a] = "   Hjärter " + (a+1).ToString();
                }
                if (a > 12 && a <= 25)
                {
                    Cards[a] = "   Ruter " + (a-12).ToString();
                }
                if (a > 25 && a <= 38)
                {
                    Cards[a] = "   Spader " + (a-25).ToString();
                }
                if (a > 38)
                {
                    Cards[a] = "   Klöver " + (a-38).ToString();
                }
            }
            return Cards;  //i get wrong here saying i need to return an array and Cards[] wont work
            //because they expect a value
        }

Need to add [] to the return in method declaration to make it an array.

0

But if i just leave it like Return Cards[];
i get an error saying "syntax error value expected"

0

Nono, look at the first line of my code block, that is where the brackets go.

public string[] CreateCards()

Edited by Mike Askew

This question has already been answered. 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.