0

Im trying to convert a string to int in visual studio, but whenever i do it cant seem to pick up the thing im trying to refrence it to.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
 using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace WindowsFormsApplication5
{
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }

    private void Form1_Load(object sender, EventArgs e)
    {

    }

    private void points1_TextChanged(object sender, EventArgs e)
    {

    }



    private void button1_Click(object sender, EventArgs e)
    {
        int x = Int32.Parse(textbox1.Text);
        resultBox.Text = 
    }
}

}

I really cant find anything, since solutions online didnt seem to work at all.

Micha De Haan
  • 65
  • 1
  • 10

2 Answers2

1

You can try using int.TryParse: try parsing textbox1.Text into int, on success put textbox1.Text itself as a result; on fail, let's write, say, "?":

int x;

resultBox.Text = int.TryParse(textbox1.Text, out x) ? textbox1.Text : "?";
Dmitry Bychenko
  • 180,369
  • 20
  • 160
  • 215
1

Try This ;

    int x = Int32.Parse(TextBox1.Text);

or this ;

    int x = 0;

    Int32.TryParse(TextBox1.Text, out x);
bakin
  • 45
  • 8