How can I convert String to Int?

后端 未结 30 2210
情歌与酒
情歌与酒 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:20

    int x = 0;
    int.TryParse(TextBoxD1.Text, out x);
    

    The TryParse statement returns a boolean representing whether the parse has succeeded or not. If it succeeded, the parsed value is stored into the second parameter.

    See Int32.TryParse Method (String, Int32) for more detailed information.

提交回复
热议问题