-5

I am just new at C# and I want to know how to convert variables I am using visual basic

String no1 = first.Text;
String no2 = second.Text;
String ans;
ans = no1 + no2;
MessageBox.Show(ans);

what is wrong in my code? the first and second .Text is textbox's name pls help

MethodMan
  • 18,625
  • 6
  • 34
  • 52
SURACI
  • 1
  • 1
  • @SURACI, you could have found this in less than a few seconds by doing a simple google search.. come on now.. do you need the url to google.com..? – MethodMan Aug 25 '16 at 18:09

2 Answers2

0

Like this:

String no1 = first.Text;
String no2 = second.Text;
int ans = Int32.Parse(no1) + Int32.Parse(no2);

MessageBox.Show(ans.ToString());
Umair M
  • 10,298
  • 6
  • 42
  • 74
0
    private void btnAdd_Click(object sender, EventArgs e)
    {
        AddNumbers(first.Text, second.Text);
    }

    private void AddNumbers(string text1, string text2)
    {
        string no1 = text1;
        string no2 = text2;
        int ans = (Convert.ToInt32(no1) + Convert.ToInt32(no2));
        MessageBox.Show(" " + ans.ToString());
    }
earlleaps
  • 43
  • 1
  • 1
  • 4