hey just wondering if you can make an method that you input a string and convert it in the method and return a int?

something like

public string[] ConvertString(string[] Cards)
        {
            int[] intCards = new int[52];
            for (int a = 0; a <= 51; a++)
            {
                int.TryParse(Cards[a], out intCards[a]);
            }
            return intCards;
        }

thank you for your replies

You have two options to convert a string to an integer, convert and tryparse.

string TempString = 0;
int OutInt = Convert.ToInt32(TempString); // This will exception if not viable to convert to integer

string TempString = 0;
bool Success;
int OutInt;
Success = int.TryParse(TempString, out OutInt); // This will return true if the convert was successful and false if it wasn't but will NOT exception and is generally the better practice.

thank you

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.