How can I convert String to Int?

后端 未结 30 2223
情歌与酒
情歌与酒 2020-11-21 05:35

I have a TextBoxD1.Text and I want to convert it to an int to store it in a database.

How can I do this?

30条回答
  •  不思量自难忘°
    2020-11-21 06:22

    If you're looking for the long way, just create your one method:

    static int convertToInt(string a)
        {
            int x = 0;
    
            Char[] charArray = a.ToCharArray();
            int j = charArray.Length;
    
            for (int i = 0; i < charArray.Length; i++)
            {
                j--;
                int s = (int)Math.Pow(10, j);
    
                x += ((int)Char.GetNumericValue(charArray[i]) * s);
            }
            return x;
        }
    

提交回复
热议问题