• 0

[C# Help] Convert string to int


Question

How can I transform a string to an int, then output that int to a textbox again? I made the thread title Convert string to int, because I will use this for int, long, double ... etc.

       private void GetAnswer_Click(object sender, EventArgs e)
        {
            string di = diameter.Text; /* diameter is the input textbox */
            float pi = di;
            answer.Text = pi; /* answer is the answer textbox */
        }

Link to comment
Share on other sites

6 answers to this question

Recommended Posts

  • 0

[C#]

int.Parse(string);

or

System.Convert.ToInt32(string);

the string must be in the correct format otherwise it'll throw an exception

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.