Converting string to int using C#

后端 未结 4 1505
日久生厌
日久生厌 2020-12-12 01:48

I am using C# and I want to convert a string to int to verify name. For example ** or 12 is not a name. I just want to convert the string into ASCI

4条回答
  •  眼角桃花
    2020-12-12 02:14

    Converting back and forth is simple:

    int i = int.Parse("42");
    string s = i.ToString();
    

    If you do not know that the input string is valid, use the int.TryParse() method.

提交回复
热议问题