0

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

2
Contributors
2
Replies
4
Views
5 Years
Discussion Span
Last Post by Dendei
0

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.

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.